How do you count the amount of zero rows of a numpy array?
array = np.asarray([[1,1],[0,0],[1,1],[0,0],[0,0]])
-> has three rows with all zero's, hence should give 3
Took me sometime to figure out this one and also couldn't find an answer on SO
You could also leverage the "truthiness" of non-zero values in an array.
np.sum(~array.any(1))
i.e., sum the rows where none of the values in said row are truthy (and hence are all zero)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With