在比较这两个不同但相似的numpy数组时,我一直试图获得True的评估。它们是我将路径与地图其余部分隔离开的图像,我试图让它识别(在一定阈值内)相同的路径交叉点。从我的研究中,我认为np.allclose()是可行的方法,但我不断获得
ValueError:操作数不能与形状一起广播(477,1920)(588,1920) 我已经尝试过np.testing_assert_almost_equal(),但是遇到类似的错误。
np.allclose()是正确的方向吗,只是做错了,还是我想做的事情有更好的功能。
附件是2个numpy数组文本文件的并排图片。任何帮助是极大的赞赏。
import numpy as np
# I have a numpy array that has isolated an intersection in a trial map/path
from an image,
# I'm trying to get it to recognise the intersection (to a certain degree as
it approaches) so
# I have a second numpy array that represents the trail map/path slightly
before you are actually to
# the point where the intersection is. So the 2 numpy arrays are different
sizes because the second one
# has the intersection slightly higher up in the image because you just
havent reached that point yet. But the
# arrays are still pretty similar. So I would want it to return True that
they are almost the same Array and
# so I figured using np.allclose() with a threshold would work just fine.
However
# I keep getting "ValueError: operands could not be broadcast together with
shapes (477,1920) (588,1920)". When I try np.allclose()
def main():
# Intersection array I am looking for
intersectArray = np.loadtxt('Intersection.txt', dtype=int)
# an array just before I've reached the same point at the intersection
intersectArrayApproach = np.loadtxt('IntersectionApproach.txt',
dtype=int)
print(np.allclose(intersectArray, intersectArrayApproach, .5,
equal_nan=True))
main()