Search code examples
pythonnumpytypeerrorlist-comprehension

Trying to access and print specific indices of an array using a list of the required index numbers


I have an array of shape (8790,8) so a large list of information. I created a filter so I can access specific indices of this array. For example - my list is something like (79,2345,4544,6789,6790). I want to use this list to print the full corresponding indices in my original array. I tried this....

For i in finalList:
    if origArray[i][6] == choice:
        outputList.append(i)
        print(outputList)

I get TypeError: 'int' object not iterable.


Solution

  • the problem must be the declaration of the variable finalList This works fine

    >>> finalList = (79,2345,4544,6789,6790)
    >>> for i in finalList:
    ...   print(i)
    ...
    79
    2345
    4544
    6789
    6790