
numpy.savetxt — NumPy v2.2 Manual
numpy.savetxt # numpy.savetxt(fname, X, fmt='%.18e', delimiter=' ', newline='\n', header='', footer='', comments='# ', encoding=None) [source] # Save an array to a text file. Parameters: fnamefilename, file handle or pathlib.Path
numpy.loadtxt — NumPy v2.2 Manual
>>> import numpy as np >>> from io import StringIO # StringIO behaves like a file object >>> c = StringIO("0 1\n2 3") >>> np.loadtxt(c) array([[0., 1.], [2., 3.]])
Reading and writing files — NumPy v2.3.dev0 Manual
>>> np.genfromtxt("csv.txt", delimiter=",", dtype=np.int8, filling_values=99) array([[ 1, 2, 3], [ 4, 99, 6], [ 7, 8, 9]], dtype=int8)
numpy.genfromtxt — NumPy v2.2 Manual
Load data from a text file, with missing values handled as specified. Each line past the first skip_header lines is split at the delimiter character, and characters following the comments character are discarded.
Input and output — NumPy v2.2 Manual
The format of these binary file types is documented in numpy.lib.format Text files #
numpy.fromfile — NumPy v2.2 Manual
Construct an array from data in a text or binary file. A highly efficient way of reading binary data with a known data-type, as well as parsing simply formatted text files.
numpy.fromstring — NumPy v2.2 Manual
numpy.fromstring # numpy.fromstring(string, dtype=float, count=-1, *, sep, like=None) # A new 1-D array initialized from text data in a string. Parameters: stringstr A string containing the data. dtypedata-type, optional The data type of the array; default: float. For binary input data, the data must be in exactly this format.
numpy.array2string — NumPy v2.2 Manual
Return a string representation of an array. Parameters: andarray Input array. max_line_widthint, optional Inserts newlines if text is longer than max_line_width. Defaults to numpy.get_printoptions()['linewidth']. precisionint or None, optional Floating point precision. Defaults to numpy.get_printoptions()['precision']. suppress_smallbool, optional
Importing data with genfromtxt — NumPy v2.2 Manual
>>> data = "\n".join(str(i) for i in range(10)) >>> np.genfromtxt(StringIO(data),) array([0., 1., 2., 3., 4., 5., 6., 7., 8., 9.]) >>> np.genfromtxt(StringIO(data), ... skip_header=3, skip_footer=5) array([3., 4.])
numpy.load — NumPy v2.2 Manual
>>> a=np.array([[1, 2, 3], [4, 5, 6]]) >>> b=np.array([1, 2]) >>> np.savez('/tmp/123.npz', a=a, b=b) >>> data = np.load('/tmp/123.npz') >>> data['a'] array([[1, 2, 3], [4, 5, 6]]) >>> data['b'] array([1, 2]) >>> data.close()