Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Efficiently #count #elements #numpy
ADD COMMENT
Topic
Name
6+8 =