I have a numpy array and I want to return the count of true values for each row.
for example I have a numpy array:
[[False False False ..., False False False]
[False False False ..., False False False]
[False False False ..., False True False]
...,
[False False False ..., False False False]
[ True False True ..., True True True]
[False False False ..., False False False]]
and the return value should be like:
[10
15
8
...,
11
10
12]
This question asks about how to do it for the whole array but how do I do it for each row?
We can simply do this by providing an axis argument to the sum function:
arr.sum(axis=1)
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