Ask Your Question
1

How can a symengine matrix be saved to a file in Python?

asked 2021-12-27 11:00:00 +0000

djk gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-06-13 21:00:00 +0000

scrum gravatar image

You can use the NumPy library to convert the Symengine matrix to a NumPy array, which can then be saved to a file using the NumPy's save function.

import numpy as np
from symengine import Matrix

# create a Symengine matrix
M = Matrix([[1, 2], [3, 4]])

# convert the matrix to a NumPy array
N = np.array(M.tolist())

# save the NumPy array to a file
np.save('matrix.npy', N)

To load the saved matrix from the file, you can use the NumPy's load function:

# load the saved matrix from the file
N = np.load('matrix.npy')

# convert the NumPy array back to a Symengine matrix
M = Matrix(N)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-12-27 11:00:00 +0000

Seen: 7 times

Last updated: Jun 13 '21