float/int operation on Matrix?

29 views
Skip to first unread message

Oyster

unread,
Dec 8, 2015, 12:58:25 AM12/8/15
to sympy
If we do not use enumeration, can we do float/int on every Matrix element? I ask this because I want to show my result while round the float number to integer. Thanks
 
 
currently
 
>>> from sympy import *
>>> X=Matrix([1.0, 2.0, 3.14])
>>> print X
Matrix([[1.00000000000000], [2.00000000000000], [3.14000000000000]])
>>> print X.evalf(1)     #in fact, I need Matrix([[1], [2], [3]])
Matrix([[1.], [2.], [3.]])
>>> print int(X.evalf(1))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: int() argument must be a string or a number, not 'MutableDenseMatrix'

Aaron Meurer

unread,
Dec 8, 2015, 3:04:18 PM12/8/15
to sy...@googlegroups.com
Use X.applyfunc(Integer), or X.applyfunc(round) if you want to round
(Integer will truncate).

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 http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/f2bf4a42-a4de-4e43-8b48-d7bf9837643c%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages