2016-11-07 46 views
1

我使用下面的代码片段来获取唯一数组的列表,但它以一种奇怪的方式重新排列列表。 uniquecoords每次都必须是相同的顺序还是有任何随机因素?numpy独一无二总是一样吗?

for c in coordiantes: 
    coords.extend(c) 
a = np.array(coords) 
uniquecoords = np.unique(
    a.view(
     np.dtype((np.void, a.dtype.itemsize*a.shape[1]))) 
    ).view(a.dtype).reshape(-1, a.shape[1]) 

回答

1

根据doc of numpy.unique(),函数“Returns a sorted unique elements of a array。”。所以订单应该永远是一样的。

如果你想保持原来的顺序,你可以做

_, idx = np.unique(your_array_of_views, return_index=True) 

uniquecoords = a[idx]