0
How to find an index of value of an ndarray inside a list?
So I want the return to be an index only. Here is the code: >>>Import numpy as np >>> a =[[111, 222], [333, 44445]] >>> type(a) <class âlistâ> I want a single line code if possible to print the index of a value. For example if I need to find the index of 111 in the list the code should return value 0 only. I have tried to convert the list back to an array as follows: >>> b = np.asarray(a) >>> np.where(b==111) (array[0], array[0] This method returns an array which is not what I want. I want the index
5 Answers
+ 2
Rea Hi ,
what result are you expecting when searching for 333? is it index 2?
it looks like you are considering the input list as a flattened list like
[111, 222, 333, 44445] .
+ 1
I solved it myself. Here is the way np.where(b==â333â)[0][0]
0
Yaroslav Vernigora None of those answer my question about ndarray inside a list. I tried them all but nothing worked. Am I missing something?
0
Lothar I want to find the array index number. So if If I am looking for 333 I should get index 1