0

How to check for a given NumPy array of any dimension (1D, 2D, or 3D) if it contains any zero floating point value (0.0). For example, this 2D array:

[[0.07181809 0.76638862 0.0]
 [0.93566192 0.13161751 0.85768675]]

Is there any function that check for above condition and return True. Thanks for the help.

3
  • 1
    np.isclose(arr, 0).any() Commented Feb 4, 2019 at 1:47
  • you can also do not np.all(arr) Commented Feb 4, 2019 at 1:53
  • It turns out that checking with 0 in arr is fastest of 3 method listed here. not np.all(arr)` and np.isclose(arr, 0).any() takes more time than simple in. Commented Feb 4, 2019 at 2:32

1 Answer 1

1

You can use :

my_numpy_array = numpy.array(
  [[0.07181809, 0.76638862, 0.0],
   [0.93566192, 0.13161751, 0.85768675]]
)
0.0 in my_numpy_array

See also: Check if single element is contained in Numpy Array.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.