I have the following symmetric matrix in sympy
:
m = sympy.Matrix([[x**2, x**3, x**4],
[x**3, x**5, x**6],
[x**4, x**6, x**7]])
My goal is to obtain the upper triangle of this matrix as a flattened array, like [x**2, x**3, x**4, x**5, x**6, x**7]
, that can be processed by lambdify
.
I used In numpy
to auxiiate achieving this:
f = lambdify((x), sympy.Matrix(np.array(m)[np.triu_indices(m.shape[0])]))
So that f(2.)
gives:
[[ 4. 8. 16. 32. 64. 128.]]
The questions is:
- is there a native way to do this in
sympy
?
Bonus:
- is there a way to obtain a
1D-array
instead of amatrix
?