np.count_nonzero()
np.count_nonzero(arr)
Returns the number of non-zero entries in arr
. True counts as 1, False counts as 0.
- Input:
- arr : array
- The array to count non-zero entries in.
- Returns:
- The number of non-zero entries in the array.
- Return Type:
- integer
is_cat_arr = np.array(pets.get('Is_Cat'))
is_cat_arr
array([False, True, True, False, False, False, False, True])
np.count_nonzero(is_cat_arr)
3
age_arr = np.array(pets.get('Age'))
age_arr
array([5. , 0.2, 9. , 2. , 0.5, 3. , 0.2, 0. ])
np.count_nonzero(age_arr)
7