import numpy as np
nums = np.array([[5.54, 3.38, 7.99],
[3.54, 8.32, 6.99],
[1.54, 2.39, 9.29]])
print("Original array:")
print(nums)
n = 8.32
r = 18.32
print("\nReplace elements of the said array which are equal to ",n,"with",r)
print(np.where(nums == n, r, nums))
print("\nReplace elements with of the said array which are less than",n,"with",r)
print(np.where(nums < n, r, nums))
print("\nReplace elements with of the said array which are greater than",n,"with",r)
print(np.where(nums > n, r, nums))
Sample Output:
Original array:
[[5.54 3.38 7.99]
[3.54 8.32 6.99]
[1.54 2.39 9.29]]
Replace elements of the said array which are equal to 8.32 with 18.32
[[ 5.54 3.38 7.99]
[ 3.54 18.32 6.99]
[ 1.54 2.39 9.29]]
Replace elements with of the said array which are less than 8.32 with 18.32
[[18.32 18.32 18.32]
[18.32 8.32 18.32]
[18.32 18.32 9.29]]
Replace elements with of the said array which are greater than 8.32 with 18.32
[[ 5.54 3.38 7.99]
[ 3.54 8.32 6.99]
[ 1.54 2.39 18.32]]
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer