Q:

Write a NumPy program to test whether any of the elements of a given array is non-zero

0

Write a NumPy program to test whether any of the elements of a given array is non-zero.

All Answers

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

import numpy as np
x = np.array([1, 0, 0, 0])
print("Original array:")
print(x)
print("Test whether any of the elements of a given array is non-zero:")
print(np.any(x))
x = np.array([0, 0, 0, 0])
print("Original array:")
print(x)
print("Test whether any of the elements of a given array is non-zero:")
print(np.any(x))

Sample Output:

Original array:
[1 0 0 0]
Test whether any of the elements of a given array is non-zero:
True
Original array:
[0 0 0 0]
Test whether any of the elements of a given array is non-zero:
False

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