Input and Output

NPZ files

cupy.load(file, mmap_mode=None)[source]

Loads arrays or pickled objects from .npy, .npz or pickled file.

This function just calls numpy.load and then sends the arrays to the current device. NPZ file is converted to NpzFile object, which defers the transfer to the time of accessing the items.

Parameters:
  • file (file-like object or string) – The file to read.
  • mmap_mode (None, 'r+', 'r', 'w+', 'c') – If not None, memory-map the file to construct an intermediate numpy.ndarray object and transfer it to the current device.
Returns:

CuPy array or NpzFile object depending on the type of the file. NpzFile object is a dictionary-like object with the context manager protocol (which enables us to use with statement on it).

See also

numpy.load()

cupy.save(file, arr)[source]

Saves an array to a binary file in .npy format.

Parameters:
  • file (file or str) – File or filename to save.
  • arr (array_like) – Array to save. It should be able to feed to cupy.asnumpy().

See also

numpy.save()

cupy.savez(file, *args, **kwds)[source]

Saves one or more arrays into a file in uncompressed .npz format.

Arguments without keys are treated as arguments with automatic keys named arr_0, arr_1, etc. corresponding to the positions in the argument list. The keys of arguments are used as keys in the .npz file, which are used for accessing NpzFile object when the file is read by cupy.load() function.

Parameters:
  • file (file or str) – File or filename to save.
  • *args – Arrays with implicit keys.
  • **kwds – Arrays with explicit keys.

See also

numpy.savez()

cupy.savez_compressed(file, *args, **kwds)[source]

Saves one or more arrays into a file in compressed .npz format.

It is equivalent to cupy.savez() function except the output file is compressed.

See also

cupy.savez() for more detail, numpy.savez_compressed()

String formatting

cupy.array_repr(arr, max_line_width=None, precision=None, suppress_small=None)[source]

Returns the string representation of an array.

Parameters:
  • arr (array_like) – Input array. It should be able to feed to cupy.asnumpy().
  • max_line_width (int) – The maximum number of line lengths.
  • precision (int) – Floating point precision. It uses the current printing precision of NumPy.
  • suppress_small (bool) – If True, very small numbers are printed as zeros
Returns:

The string representation of arr.

Return type:

str

cupy.array_str(arr, max_line_width=None, precision=None, suppress_small=None)[source]

Returns the string representation of the content of an array.

Parameters:
  • arr (array_like) – Input array. It should be able to feed to cupy.asnumpy().
  • max_line_width (int) – The maximum number of line lengths.
  • precision (int) – Floating point precision. It uses the current printing precision of NumPy.
  • suppress_small (bool) – If True, very small number are printed as zeros.