Ask Your Question

Revision history [back]

Thanks for reporting.

One alternative approach would be, after creating the array a, instead of multiplying by x and then converting to a matrix, to first convert to a matrix and then multiply by x.

Create the array a:

sage: import numpy as np
sage: a = np.zeros((5, 5), dtype='complex')
sage: np.fill_diagonal(a, 1)
sage: x = SR.var('x')
sage: b = x*a
sage: a
array([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],
       [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],
       [0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j],
       [0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j],
       [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j]])

From the question: multiply array by x, then convert to matrix:

sage: b
array([[((1+0j))*x, 0j, 0j, 0j, 0j],
       [0j, ((1+0j))*x, 0j, 0j, 0j],
       [0j, 0j, ((1+0j))*x, 0j, 0j],
       [0j, 0j, 0j, ((1+0j))*x, 0j],
       [0j, 0j, 0j, 0j, ((1+0j))*x]], dtype=object)
sage: c = matrix(b)
sage: c
[((1+0j))*x         0j         0j         0j         0j]
[        0j ((1+0j))*x         0j         0j         0j]
[        0j         0j ((1+0j))*x         0j         0j]
[        0j         0j         0j ((1+0j))*x         0j]
[        0j         0j         0j         0j ((1+0j))*x]
sage: c.parent()
Full MatrixSpace of 5 by 5 dense matrices over Symbolic Ring

sage: c.inverse()
Traceback (most recent call last)
...
TypeError: ECL says: THROW: The catch MACSYMA-QUIT is undefined.

Alternative approach: convert to matrix, then multiply by x:

sage: b = matrix(a)
sage: b
[1.0 0.0 0.0 0.0 0.0]
[0.0 1.0 0.0 0.0 0.0]
[0.0 0.0 1.0 0.0 0.0]
[0.0 0.0 0.0 1.0 0.0]
[0.0 0.0 0.0 0.0 1.0]
sage: b.parent()
Full MatrixSpace of 5 by 5 dense matrices over Complex Double Field

sage: c = x * b
sage: c
[1.0*x   0.0   0.0   0.0   0.0]
[  0.0 1.0*x   0.0   0.0   0.0]
[  0.0   0.0 1.0*x   0.0   0.0]
[  0.0   0.0   0.0 1.0*x   0.0]
[  0.0   0.0   0.0   0.0 1.0*x]
sage: c.parent()
Full MatrixSpace of 5 by 5 dense matrices over Symbolic Ring

sage: c.inverse()
[1.0/x     0     0     0     0]
[    0 1.0/x     0     0     0]
[    0     0 1.0/x     0     0]
[    0     0     0 1.0/x     0]
[    0     0     0     0 1.0/x]