How do I count the number of 0
s and 1
s in the following array?
y = np.array([0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1])
y.count(0)
gives:
numpy.ndarray
object has no attributecount
countmultidimensional-arraynumpypython
How do I count the number of 0
s and 1
s in the following array?
y = np.array([0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1])
y.count(0)
gives:
numpy.ndarray
object has no attributecount
Best Answer
Using
numpy.unique
:Non-numpy method using
collections.Counter
;