gpt4 book ai didi

numpy 运算符来比较两个向量

转载 作者:行者123 更新时间:2023-12-04 10:18:25 30 4
gpt4 key购买 nike

我想知道是否有一个 python-numpy 运算符来比较两个相同形状的向量。具体来说,
enter image description here

我可以通过 numpy API 直接获取结果吗?它是什么?非常感谢!

最佳答案

如果您的数组是 a 和 b:

c = ((np.repeat(a, b.shape[0]).reshape(a.shape[0], b.shape[0]) - b) == 0).astype(int)

或者,正如 hpaulj 和 FBruzzesi 所说:
c = (a[:, None] == b).astype(int)

关于numpy 运算符来比较两个向量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60976313/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com