I have a problem using the sympy library. I want to transpose a matrix but it does not work. My code is
x = Symbol('x')
y = Symbol('y')
J = Matrix([[1+x,2+y,3*x],[4*x,5+x,6*y],[7+y,8*y,9+x]])
Jtrans = Transpose(J)
print(J)
print(Jtrans)
Any suggestions?
Use the shorthand J.T
.
>>> J
Matrix([
[x + 1, y + 2, 3*x],
[ 4*x, x + 5, 6*y],
[y + 7, 8*y, x + 9]])
>>> Transpose(J)
Matrix([
[x + 1, y + 2, 3*x],
[ 4*x, x + 5, 6*y],
[y + 7, 8*y, x + 9]])'
>>> #'
>>> J.T
Matrix([
[x + 1, 4*x, y + 7],
[y + 2, x + 5, 8*y],
[ 3*x, 6*y, x + 9]])
it is working fine for me:
Matrix([[x + 1, y + 2, 3*x], [4*x, x + 5, 6*y], [y + 7, 8*y, x + 9]])
Matrix([
[x + 1, y + 2, 3*x],
[ 4*x, x + 5, 6*y],
[y + 7, 8*y, x + 9]])'
Note the small '
after the second matrix? That's your transpose operation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With