这个问题在这里已经有了答案:
What are the differences between numpy arrays and matrices? Which one should I use?
(6 个回答)
去年关闭。
我有以下片段。
values = [[0.1, 0.7, 0.5], [0.6, 0.3, 0.2], [0.2, 0.8, 0.77]]
A = np.array(values).reshape(3,3)
print A.shape
print np.mean(A, axis=1)
B = np.mat(np.random.rand(3, 3));
print B.shape
print np.mean(B, axis=1)
打印语句的输出:
(3, 3)
[ 0.43333333 0.36666667 0.59 ]
(3, 3)
[[ 0.47252016]
[ 0.44380355]
[ 0.51070646]]
我有两个具有不同值的相同形状的 numpy 数组作为输入,一个是使用
rand
生成的另一个函数是用 array
创建的 python 列表。函数并在其上调用 reshape。但是,即使输入形状相同,两者的平均 yield 形状也是不同的。有什么想法会导致这种情况吗?
最佳答案
如 numpy.matrix
的文档中所述,
A matrix is a specialized 2-D array that retains its 2-D nature through operations
此外,
It is no longer recommended to use this class, even for linear algebra. Instead use regular arrays. The class may be removed in the future.
关于python - Numpy 形状相同,均值返回不同的形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59818048/