我已经生成了列表项之间成对距离的矩阵,但出现了一些问题,它是不对称的。你知道吗
如果矩阵如下所示:
array = np.array([
[0, 3, 4],
[3, 0, 2],
[1, 2, 0]
])
如何确定实际的不对称性?在本例中,索引4和1。你知道吗
我用scipy平方函数压缩矩阵,然后用
def check_symmetric(a, rtol=1e-05, atol=1e-08):
return np.allclose(a, a.T, rtol=rtol, atol=atol)
Tags:
以下是快速和缓慢,但如果对象是调试可能会做。你知道吗
定义函数以查找和打印差异。你知道吗
这个版本将结果的体积减半。你知道吗
您可以简单地使用
np.isclose()
的否定:将该值用作索引以获取值:
如果需要索引,请使用
np.where()
:很晚了,但这里会有一个替代的方式。。。你知道吗
输出:
相关问题 更多 >
编程相关推荐