Reputation: 87
import sympy
I am trying to find a matrix after taking each of its values (mod n). I know numpy arrays work fine with this but i have to use sympy unfortunately. Does anyone know of an inbuilt sympy function that does this or any other way round it? Thank you!
B = sympy.Matrix([[2, 3], [4, 5]])
print(B % 3)
This is my error
TypeError: unsupported operand type(s) for %: 'MutableDenseMatrix' and 'int'
with numpy this is the correct output:
B = np.array([[2, 3], [4, 5]])
print(B % 3)
>>> [[2 0]
[1 2]]
Upvotes: 2
Views: 1457
Reputation: 19135
With current SymPy this works:
>>> import sympy
>>> B = sympy.Matrix([[2, 3], [4, 5]])
>>> print(B % 3)
Matrix([[2, 0], [1, 2]])
Upvotes: 0
Reputation: 412
You can use applyfunc to apply a function to every element:
B.applyfunc(lambda x : x % 3)
Upvotes: 1