Q:

Write a NumPy program to extract all numbers from a given array which are less and greater than a specified number

0

Write a NumPy program to extract all numbers from a given array which are less and greater than a specified number.

All Answers

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

import numpy as np  
nums = np.array([[5.54, 3.38, 7.99],
              [3.54, 4.38, 6.99],
              [1.54, 2.39, 9.29]])
print("Original array:")
print(nums)
n = 5
print("\nElements of the said array greater than",n)
print(nums[nums > n])
n = 6
print("\nElements of the said array less than",n)
print(nums[nums < n])

Sample Output:

Original array:
[[5.54 3.38 7.99]
 [3.54 4.38 6.99]
 [1.54 2.39 9.29]]

Elements of the said array greater than 5
[5.54 7.99 6.99 9.29]

Elements of the said array less than 6
[5.54 3.38 3.54 4.38 1.54 2.39]

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