SymPy Matrix class to Numpy array class in Python

801 views
Skip to first unread message

Math newbie

unread,
Jul 19, 2018, 8:05:32 AM7/19/18
to sympy
Let's say I have a matrix M in the SymPy Matrix class, how may I create a Numpy array variable that takes the same values as in M?

I tried np.array(M). But its dtype=Object which is strange and I am not sure what does it mean.

Any idea would be extremely helpful! Thanks!

Aaron Meurer

unread,
Jul 19, 2018, 5:32:12 PM7/19/18
to sy...@googlegroups.com
Ideally you should be able to just do np.array(Matrix(...),
dtype=float) (or dtype=int) to create a numpy array with a native
dtype. But it looks like there is a bug that prevents it from working
(https://github.com/sympy/sympy/issues/14943). So for now you can use

from sympy import matrix2numpy
matrix2numpy(M, dtype=float)

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/baf3cffc-c2d6-477e-b8f5-5eef71a9f886%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Math newbie

unread,
Jul 19, 2018, 8:48:37 PM7/19/18
to sympy
Thanks Aaron. 
Reply all
Reply to author
Forward
0 new messages