2016-11-07 32 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]