You can pass the whole expression as a string to sympify(rational=True),
like
sympify('Matrix([[0.8, 0.2], [0.6, 0.4]])', rational=True)
You can also use nsimplify() on the expression after it is created, but
this may result in different numbers in some cases because of the
inexactness of floating point numbers.
Aaron Meurer
On Tue, Apr 11, 2017 at 12:52 PM, chaowen guo <[email protected]> wrote:
> Hi:
>
> I want to create a sympy matrix from string floating and I want to get
> exact values not just floating point, so I have to specify sympy.Rational
> every time as follows:
>
>
>
> I want to ask is there any easier way to specify sympy.Rational only once,
> maybe something like dtype in numpy? say:
> sympy.Matrix([['0.8','0.2'],['0.6','0.4']],dtype=sympy.Rational)
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> 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/d6f51c14-3ce8-4fa5-b021-4c50f29f1d77%40googlegroups.com
> <https://groups.google.com/d/msgid/sympy/d6f51c14-3ce8-4fa5-b021-4c50f29f1d77%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
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 [email protected].
To post to this group, send email to [email protected].
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/CAKgW%3D6KyLtAO0BZvCn%2BasrjVq5PCfELR3Y%2BJqkyS3AtTw5gGvA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.