+1 vote
in Programming Languages by (74.2k points)

The following code is returning the following error: TypeError: '>' not supported between instances of 'list' and 'int'

>>> a=[1,0,1,2,0,0,3,4,1]

>>> np.where(a>0)

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

TypeError: '>' not supported between instances of 'list' and 'int'

How to fix this error? 

1 Answer

+3 votes
by (351k points)
selected by
 
Best answer

You are applying numpy where() function to a list. That's why your code is giving the error. You need to convert the list to numpy array to fix the error.

Here is the fix:

>>> import numpy as np
>>> a=[1,0,1,2,0,0,3,4,1]
>>> np.where(np.asarray(a)>0)

(array([0, 2, 3, 6, 7, 8]),)
>>>
 


...