如果您输入一个包含一般对象的数组到numpy.unique
,结果将基于什么是唯一的?
我努力了:
import numpy as np
class A(object): #probably exists a nice mixin for this :P
def __init__(self, a):
self.a = a
def __lt__(self, other):
return self.a < other.a
def __le__(self, other):
return self.a <= other.a
def __eq__(self, other):
return self.a == other.a
def __ge__(self, other):
return self.a >= other.a
def __gt__(self, other):
return self.a > other.a
def __ne__(self, other):
return self.a != other.a
def __repr__(self):
return "A({})".format(self.a)
def __str__(self):
return self.__repr__()
np.unique(map(A, range(3)+range(3)))
返回
array([A(0), A(0), A(1), A(1), A(2), A(2)], dtype=object)
但我的意图是:
array([A(0), A(1), A(2)], dtype=object)