Error substituting SymbolMatrix with values in Python 2.7

467
February 12, 2017, at 1:13 PM

I am trying to substitute a sympy symbolic matrix that I created with some real numbers. However, I get an error which I am not able to solve. Can anyone provide me a working solution to fix this issue in Python 2.7, sympy 1.0?

This is the code :

import sympy as sy
from sympy import Symbol
x1 = sy.MatrixSymbol('x1', 2, 2)
x2 = 2*x1
print x2.subs({x1: sy.Matrix([[2,1],[1,-3]])})

However, when I run the above code, I get the following error:

Traceback (most recent call last):
File "ID.py", line 5, in <module>
print x2.subs({x1: sy.Matrix([[2,1],[1,-3]])})
File "/usr/lib/python2.7/dist-packages/sympy/core/basic.py", line 859, in subs
ops = o.count_ops(), len(o.args)
File "/usr/lib/python2.7/dist-packages/sympy/core/basic.py", line 1484, in count_ops
return count_ops(self, visual)
File "/usr/lib/python2.7/dist-packages/sympy/core/function.py", line 2321, in count_ops
ops = [count_ops(i, visual=visual) for i in expr]
File "/usr/lib/python2.7/dist-packages/sympy/core/function.py", line 2252, in count_ops
if a.is_Rational:
AttributeError: 'str' object has no attribute 'is_Rational'
Rent Charter Buses Company
READ ALSO
Python3 - Can we use for loop to iterate over a dict of dicts?

Python3 - Can we use for loop to iterate over a dict of dicts?

I have a dict of nested dicts and key-values

602
Failure to change identify using Tor when scraping google

Failure to change identify using Tor when scraping google

I am trying to automate google search but unfortunately my IP is blockedAfter some searches, it seems like using Tor could get me a new IP dynamically

409
How to get the binary and library folders&#39; path in Linux?

How to get the binary and library folders' path in Linux?

Let's say that I am writing a Python program on LinuxAnd I want to run a binary manually-installed command called "foo" using its path

345