Reputation: 1421
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?
Upvotes: 4
Views: 3350
Reputation: 1421
We can simply do this by providing an axis
argument to the sum
function:
arr.sum(axis=1)
Upvotes: 8