简体   繁体   English

numpy独特的奇怪行为

[英]numpy unique strange behaviour

according to the official numpy.unique documentation ( http://docs.scipy.org/doc/numpy/reference/generated/numpy.unique.html ) return_index=True should allow me to recover the first occurrences of elements in an array. 根据官方的numpy.unique文档( http://docs.scipy.org/doc/numpy/reference/generated/numpy.unique.html),return_index = True应该允许我恢复数组中元素的第一次出现。 However, this does not work for this simple example: 但是,这不适用于以下简单示例:

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

This results in: 结果是:

[mvogelsberger@itc021 ~]$ python test.py 
6685 999

Clearly, 6685 is not the index of first occurrence of 999 in the array a. 显然,6685不是数组a中首次出现的999的索引。 Can someone clarify? 有人可以澄清吗? I probably misunderstand the documentation... 我可能会误解文档...

Thanks! 谢谢! Mark 标记

正如您在评论中所猜到的,此行为确实是Numpy v1.7中修复的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM