简体   繁体   中英

Finding the Unique Arrays in an List of Arrays

I have a list of arrays, say

List = [A,B,C,D,E,...]

where each A,B,C etc. is an nxn array.

I wish to have the most efficient algorithm to find the unique nxn arrays in the list. That is, say if all entries of A and B are equal, then we discard one of them and generate the list

UniqueList = [A,C,D,E,...]

Not sure if there is a faster way, but I think this should be pretty fast (using the built-in unique function of numpy and choosing axis=0 to look for nxn unique arrays. More detail in thenumpy doc ):

[i for i in np.unique(np.array(List),axis=0)]

Example:

A = np.array([[1,1],[1,1]])
B = np.array([[1,1],[1,2]])
List = [A,B,A]

[array([[1, 1],
        [1, 1]]), 
 array([[1, 1],
        [1, 2]]), 
 array([[1, 1],
        [1, 1]])]

Output:

[array([[1, 1],
        [1, 1]]), 
 array([[1, 1],
        [1, 2]])]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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