How can I get indices of elements of nd.array not in a tulple, but in nd.array with .ndim==1 E.g. I have array [1,4,2,1] and a condition that elements should be less than 3. I tried this codenp.where(array<3) but it returned me a tuple. Then a tried to convert it into nd.array with np.array(np.where(array<3)) but after that the ndim was 2. The output of the example [1,4,2,1] Should be [0,2,3] and type(output)==nd.array
[1,4,2,1]
np.where(array<3)
np.array(np.where(array<3))
[0,2,3]
type(output)==nd.array
You're almost there:
np.where(array<3)[0]
[0] here takes the firts element of the tuple and this element is of type np.ndarray
[0]
np.ndarray
1.4m articles
1.4m replys
5 comments
56.9k users