Q:

Write a NumPy program to get the row numbers in given array where at least one item is larger than a specified value

0

Write a NumPy program to get the row numbers in given array where at least one item is larger than a specified value.

All Answers

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

import numpy as np
num = np.arange(36)
arr1 = np.reshape(num, [4, 9])
print("Original array:")
print(arr1)
result  = np.where(np.any(arr1>10, axis=1))
print("\nRow numbers where at least one item is larger than 10:")
print(result)
Sample Output:
Original array:
[[ 0  1  2  3  4  5  6  7  8]
 [ 9 10 11 12 13 14 15 16 17]
 [18 19 20 21 22 23 24 25 26]
 [27 28 29 30 31 32 33 34 35]]

Row numbers where at least one item is larger than 10:
(array([1, 2, 3]),)

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