我找不到以词典编排方式比较两个(在我的例子中是多维)数组的直接方法。
即。
a = [1,2,3,4]
b = [4,0,1,6]
对于 a < b
我想得到 true
我在哪里得到 [true, false, false, true]
对于 a > b
我想得到 false
我在哪里得到 [false, true, true, false]
最佳答案
如果问题只是关于寻找是否a
是<
或 >
比b
, 那么下面的应该工作。
def fn(a, b):
# finds index of the first non matching element
idx = np.where( (a>b) != (a<b) )[0][0]
if a[idx] < b[idx]: print "a < b"
if a[idx] > b[idx]: print "a > b"
关于python - 两个numpy ndarrays的字典序比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38044731/