我使用Python创建对称矩阵/阵列,NumPy的,利用标准方法意外的结果:与+ =上与NumPy阵列
x = rand(500,500)
x = (x+x.T)
all(x==x.T)
> True
现在,让我们变得聪明:
x = rand(500,500)
x += x.T
all(x==x.T)
> False
等待什么?
x==x.T
> array([[ True, True, True, ..., False, False, False],
[ True, True, True, ..., False, False, False],
[ True, True, True, ..., False, False, False],
...,
[False, False, False, ..., True, True, True],
[False, False, False, ..., True, True, True],
[False, False, False, ..., True, True, True]], dtype=bool)
左上角和右下角段是对称的。如果我选择更小的阵列呢?
x = rand(50,50)
x += x.T
all(x==x.T)
> True
OK ....
x = rand(90,90)
x += x.T
all(x==x.T)
> True
x = rand(91,91)
x += x.T
all(x==x.T)
> False
而只是要确定...
x = rand(91,91)
x = (x+x.T)
all(x==x.T)
> True
这是一个错误,还是我要学习的东西疯狂+=
和NumPy数组?
这个问题需要正确的标题。 – plaes 2014-10-09 12:18:33
@AndrewJaffe这是Python 3.4.1上的Numpy 1.9,分布在Anaconda。 – jeffalstott 2014-10-09 12:34:16
@jeffalstott是的,我误解了这个问题 - 我也看到了这种行为。 – 2014-10-09 12:37:47