Python numpy:查看数组是否在公差范围内对称 [英] Python numpy: see if an array is symmetric within a tolerance

查看:123
本文介绍了Python numpy:查看数组是否在公差范围内对称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个采用二维正方形数组并返回一个布尔值的函数,该值反映 a 是否在容差公差范围内对称,到 a

I'm looking to come up with a function that takes a 2-dimensional square array and returns a boolean value that reflects whether a is symmetric, within tolerance tolerance, to a.

我的代码如下:

for i in range(len(a)):
    for j in range(len(a[0])):
        if abs(a[i][j] - a.transpose()[j][i]) <= tol:
            a == a.transpose().all

并且引起我的注意,当我返回(a)时,我并没有真正返回我想要的内容,并且不确定如何解决此问题。

and its come to my attention that when i return(a) im not actually returning what I want and im not sure how to fix this.

推荐答案

您可以将计算矢量化:

def is_symmetric(a):
    return (np.abs(a - a.T) <= tol).all()

这篇关于Python numpy:查看数组是否在公差范围内对称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆