首页 > 解决方案 > 获取同情矩阵的形状

问题描述

我想知道用于调试目的的 sympy 矩阵的形状。该文档建议以下内容:

from sympy import shape
M = Matrix([[1, 2, 3], [-2, 0, 4]])
shape(M)

然而,这似乎不适用于我的 sympy 版本,甚至在集成到 sympy 文档网站的 life shell 中也不起作用。

docs.sympy.org的 life shell 中,它会引发以下错误:

>>> from sympy import shape
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: cannot import name shape

任何帮助,将不胜感激。谢谢你。

标签: pythonsympy

解决方案


尝试这个

import sympy
M = sympy.Matrix([[1, 2, 3], [-2, 0, 4]])
M.shape

我明白了

(2, 3)

推荐阅读