python - Numpy 'where' on string -
i use numpy.where function on string array. however, unsuccessful in doing so. can please me figure out?
for example, when use numpy.where on following example error:
import numpy np = ['apple', 'orange', 'apple', 'banana'] arr_index = np.where(a == 'apple',1,0) i following:
>>> arr_index array(0) >>> print a[arr_index] >>> apple however, know indices in string array, string 'apple' matches. in above string happens @ 0 , 2. however, np.where returns 0 , not 2.
so, how make numpy.where work on strings? in advance.
print a[arr_index] not array_index!!
a = np.array(['apple', 'orange', 'apple', 'banana']) arr_index = np.where(a == 'apple') print arr_index print a[arr_index]
Comments
Post a Comment