How to find an index of value of an ndarray inside a list? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
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

15th Sep 2022, 12:41 AM
Rea Hi
5 Antworten
+ 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] .
15th Sep 2022, 10:56 AM
Lothar
Lothar - avatar
+ 1
I solved it myself. Here is the way np.where(b==“333”)[0][0]
17th Sep 2022, 11:53 PM
Rea Hi
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?
15th Sep 2022, 9:16 AM
Rea Hi
0
Lothar I want to find the array index number. So if If I am looking for 333 I should get index 1
15th Sep 2022, 2:22 PM
Rea Hi