pyacs.lib.utils.save_np_array_with_string

Save numpy arrays with an additional string column.

pyacs.lib.utils.save_np_array_with_string.save_np_array_with_string(A, S, fmt, outfile, comment='')[source]

Save a numpy array as a text file with a string column per row.

Equivalent to np.savetxt but S is a 1D string array appended to each row.

Parameters:
  • A (numpy.ndarray) – 2D array to save.

  • S (array_like) – 1D string array; len(S) must equal A.shape[0].

  • fmt (str) – Format string for each row (e.g. “%03d %03d %s”).

  • outfile (str) – Output file path.

  • comment (str, optional) – Comment line written at top. Default is ‘’.

Examples

>>> A = np.arange(4).reshape(-1, 2)
>>> S = np.array(['lima', 'quito'])
>>> save_np_array_with_string(A, S, "%03d %03d %s", 'test.dat')