I have for example the following np array
array([[ True, False, False],
[False, True, True],
[ True, True, True],
[False, True, True],
[False, True, True],
[ True, False, False],
[ True, True, False],
[False, False, True]])
I want to count the number of consecutive Trues along the columns, so in the above example, the first column contains 3 blocks of consecutive Trues, the second column contains 2 blocks, and the third contains 2 blocks. The output should then be
array([3, 2, 2])
I know I can do loops for each columns, like in this answer for a one-dimensional array, but what is a numpy-way for doing this on a 2-d array?
source https://stackoverflow.com/questions/76391013/how-to-count-number-of-consecutive-trues-in-a-numpy-array-along-a-given-axis
Comments
Post a Comment