根据官方numpy.unique文档(http://docs.scipy.org/doc/numpy/reference/generated/numpy.unique.html)return_index = True应该允许我恢复数组中第一次出现的元素。但是,这不适用于这个简单的例子:
import numpy as np
a = np.array([10,20,30,40,50,60,70,80,3,2,4,3,2,5,2,1,999,1000])
a = np.append(a,np.repeat(999,10000))
u, indices = np.unique(a, return_index=True)
print indices[13], u[13] #according to unique documentation indices[13] should be 16 (i.e. first occurrence of 999 = u[13]), but it is not
这导致:
[mvogelsberger@itc021 ~]$ python test.py
6685 999
显然,6685不是数组a中第一次出现999的索引。有人可以澄清吗?我可能误解了文档......
谢谢! 标记