0

给定 5 个向量,例如:

     X1   X2
    ---------
A = [51, 134]
B = [40, 110]
C = [41, 191]
D = [35, 198]
E = [30, 140]

我试图找到类似的向量,例如 ifA[X1]>B[X1]A[X2]>B[X2],我们删除BA 并将其保留为“好”向量。如果A[X1]>B[X1]然后A[X2]<B[X2]我们保留它们。我尝试在向量之间使用余弦相似度,但结果不正确。例如,上述向量将只有 3 个剩余的“好”向量,A,C,D。比较每个属性并按列排序(部分排序)是我正在考虑的一种方式。但是如果我有d = 10属性呢?如何解决这个问题?

4

1 回答 1

0

如果我理解正确,我认为您的意思是从A[Xi] > B[Xi],您实际上是指row[Xi] > next_row[Xi]

>>> A = [51, 134]
>>> B = [40, 110]
>>> C = [41, 191]
>>> D = [35, 198]
>>> E = [30, 140]

>>> arr = np.vstack([A, B, C, D, E])
>>> arr
array([[ 51, 134],
       [ 40, 110],
       [ 41, 191],
       [ 35, 198],
       [ 30, 140]])

>>> # (row_i[X1] > row_i+1[X1]) and (row_i[X2] > row_i+1[X2])
>>> cond1 = np.cumprod(arr[:-1] > arr[1:]).all(axis=1)
>>> cond1
array([ True, False, False, False])

>>> # (row_i[X1] > row_i+1[X1]) and (row_i[X2] < row_i+1[X2])
>>> cond2 = (arr[:-1, 0] > arr[1:, 0]) | (arr[:-1, 1] > arr[1:, 1])
>>> cond2
array([ True, False,  True,  True])

>>> cond1 | cond2
array([ True, False,  True,  True])

>>> arr[:-1][cond1 | cond2]
array([[ 51, 134],  # A
       [ 41, 191],  # C
       [ 35, 198]]) # D
于 2019-11-03T00:39:36.650 回答