Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get shape of sympy matrix

Tags:

python

sympy

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.

like image 491
TheFibonacciEffect Avatar asked Jan 26 '26 03:01

TheFibonacciEffect


1 Answers

try this

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

I get

(2, 3)
like image 172
anarchy Avatar answered Jan 27 '26 16:01

anarchy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!