Answers for "count number of non zero elements numpy"

0

Efficiently count zero elements in numpy array?

In [3]: arr
Out[3]: 
array([[1, 2, 0, 3],
      [3, 9, 0, 4]])

In [4]: np.count_nonzero(arr==0)
Out[4]: 2

In [5]:def func_cnt():
            for arr in arrs:
                zero_els = np.count_nonzero(arr==0)
                # here, it counts the frequency of zeroes actually
Posted by: Guest on August-10-2020

Code answers related to "count number of non zero elements numpy"

Python Answers by Framework

Browse Popular Code Answers by Language