Q:

Write a NumPy program to fetch all items from a given array of 4,5 shape which are either greater than 6 and a multiple of 3

0

Write a NumPy program to fetch all items from a given array of 4,5 shape which are either greater than 6 and a multiple of 3.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import numpy as np
array_nums1 = np.arange(20).reshape(4,5)
print("Original arrays:")
print(array_nums1)
result = array_nums1[(array_nums1>6) & (array_nums1%3==0)]
print("\nItems greater than 6 and a multiple of 3 of the said array:")
print(result)

Sample Output:

Original arrays:
[[ 0  1  2  3  4]
 [ 5  6  7  8  9]
 [10 11 12 13 14]
 [15 16 17 18 19]]

Items greater than 6 and a multiple of 3 of the said array:
[ 9 12 15 18]

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now