4845 explained code solutions for 96 technologies

python-numpyHow to save Numpy matrix to text file

import numpy as np

matrix = np.array([[1,2], [3,4], [5,6]])
np.savetxt('/tmp/matrix.txt', matrix)ctrl + c
import numpy as np

load Numpy module for Python


declare Numpy array (or matrix)


saves specified matrix to text file


path to text file to save matrix to


matrix to save to text file