【发布时间】:2017-12-29 00:31:18
【问题描述】:
我有一个如下的 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)
¿我怎样才能使外部比较行明智而不是元素明智?
【问题讨论】: