import numpy as np
x = np.array([[0, 10, 20], [20, 30, 40]])
print("Original array:")
print(x)
print("Number of non zero elements in the above array:")
print(np.count_nonzero(x))
Sample Output:
Original array:
[[ 0 10 20]
[20 30 40]]
Number of non zero elements in the above array:
5
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer