我有一个 numpy 数组,如下所示:
a= array([[2, 3],
[0, 2]])
并希望使用 np.greater 将每行中的“向量”与其他行进行比较,因此:
array([[False, False], <--- [2,3] compared with [2,3]
[True, True]], <--- [2,3] compared with [0,2]
[[False, False], <--- [0,2] compared with [2,3]
[False, False]]) <--- [0,2] compared with [0,2]
但如果我尝试r=(np.greater.outer(a,a))
它比较中的每个数字a
与中的所有其他数字a
,因此有:
array([[[[False, False], <--- 2 compared with a
[ True, False]],
[[ True, False], <--- 3 compared with a
[ True, True]]],
[[[False, False], <--- 0 compared with a
[False, False]],
[[False, False], <--- 2 compared with a
[ True, False]]]], dtype=bool)
¿如何进行外部比较行明智而不是元素明智?