I have the following numpy array named histarr with the shape 1, 13
array([0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0], dtype=uint32)
I want to get an array that gives me positions where 1's are, hence I used np.where
where_are_ones_arr = np.where(histarr == 1)
The output is:
(array([1, 2, 4, 5, 6], dtype=int32),)
I was confused for a while but than I checked the type and I realized that where_are_ones_arr
is not an array but it is actually a tuple, so if I wanted to get an array I used:
where_are_ones_arr[0]
Result:
array([1, 2, 4, 5, 6], dtype=int32)
Now that is all fine but I found it unbelievable that I cannot get that in one line, so I looked around and tried:
where_are_ones_give_me_only_array = histarr[np.where(histarr == 1)]
But it spits out:
array([1, 1, 1, 1, 1], dtype=uint32)
Which is not what I want and what I can explain? What is it that I do not get?