我使用numpy来计算对称方阵的特征值和特征向量.我的阵列是:
L = [[ 2. -1. -1. 0. 0. 0.]
[-1. 3. 0. -1. 0. -1.]
[-1. 0. 2. -1. 0. 0.]
[ 0. -1. -1. 3. -1. 0.]
[ 0. 0. 0. -1. 2. -1.]
[ 0. -1. 0. 0. -1. 2.]]
Run Code Online (Sandbox Code Playgroud)
执行时的结果numpy.linalg.eig(L)如下所示
特征值:
[ 5.00000000e+00,
3.96872205e-16,
1.00000000e+00,
2.00000000e+00,
3.00000000e+00,
3.00000000e+00 ]
Run Code Online (Sandbox Code Playgroud)
特征向量:
[[ -2.88675135e-01 4.08248290e-01 -5.00000000e-01 4.08248290e-01 -4.36632863e-01 4.44614891e-01]
[ 5.77350269e-01 4.08248290e-01 -3.34129212e-16 4.08248290e-01 -1.08813217e-01 -5.41271705e-01]
[ 2.88675135e-01 4.08248290e-01 -5.00000000e-01 4.08248290e-01 5.45446080e-01 9.66568140e-02]
[ -5.77350269e-01 4.08248290e-01 …Run Code Online (Sandbox Code Playgroud) 我真的很困惑为什么出现此错误。这是我的代码:
import numpy as np
x = np.array([0, 0])
y = np.array([10, 10])
a = np.array([1, 6])
b = np.array([3, 7])
points = [x, y, a, b]
max_pair = [x, y]
other_pairs = [p for p in points if p not in max_pair]
>>>ValueError: The truth value of an array with more than one element is ambiguous.
Use a.any() or a.all()
(a not in max_paix)
>>>ValueError: The truth ...
Run Code Online (Sandbox Code Playgroud)
令我感到困惑的是,以下各项工作正常:
points = [[1, 2], [3, 4], [5, 7]]
max_pair = …Run Code Online (Sandbox Code Playgroud)