我正在重写一段代码
nd = unique(nd,'rows');
The Mathworks 的文档
C = unique(A,'rows')treats each row ofAas a single entity and returns the unique rows ofA. The rows of the arrayCare in sorted order.
Python 中是否有类似的东西,或者我必须使用排序?
请您参考如下方法:
import numpy as np
# Having an array:
a = [1,2,2,3,4,4,3]
print ("Original vector:")
print(a)
# Printting unique values of a:
print ("Unique values of a:")
print (np.unique(a))
# Other option:
print ("Another way:")
print (set(a))
输出:
Original vector:
[1, 2, 2, 3, 4, 4, 3]
Unique values of a:
[1 2 3 4]
Another way:
{1, 2, 3, 4}
