If you want the length of an integer as in the number of digits in the integer, you can always convert it to string like str(133) and find its length like len(str(123)).
What's the simplest way to count the number of occurrences of a character in a string?
e.g. count the number of times 'a' appears in 'Mary had a little lamb'
In Python, I have an ndarray y
that is printed as array([0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1])
I'm trying to count how many 0s and how many 1s are there in this array.
But when I type y.count(0) or y.count(1), it says
numpy.…