Get shape of sympy matrix

Viewed 536

I would like to know the shape of a sympy matrix for debugging purposes. The documentation suggests the following:

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

However this doesn't seem to work on my version of sympy and it doesn't even work in the life shell that is integrated into the sympy documentation website.

In the life shell on docs.sympy.org it throws the following error:

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

Any help would be appreciated. Thank you.

1 Answers

try this

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

I get

(2, 3)
Related