我想在字符串数组上使用 numpy.where 函数。然而,我这样做并不成功。有人可以帮我解决这个问题吗?
例如,当我使用numpy.where
在下面的示例中我收到错误:
import numpy as np
A = ['apple', 'orange', 'apple', 'banana']
arr_index = np.where(A == 'apple',1,0)
我得到以下信息:
>>> arr_index
array(0)
>>> print A[arr_index]
>>> apple
但是,我想知道字符串数组中的索引,A
字符串在哪里'apple'
火柴。在上面的字符串中,这发生在 0 和 2 处。但是,np.where
只返回0而不返回2。
那么,我该如何制作numpy.where
在弦乐上工作?提前致谢。
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])
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)