dpnp.loadtxt

dpnp.loadtxt(fname, dtype=<class 'float'>, like=None, device=None, usm_type='device', sycl_queue=None, **kwargs)[source]

Load data from a text file.

For full documentation refer to numpy.loadtxt.

Parameters:
  • fname (file, str, pathlib.Path, list of str, generator) -- File, filename, list, or generator to read. If the filename extension is .gz or .bz2, the file is first decompressed. Note that generators must return bytes or strings. The strings in a list or produced by a generator are treated as lines.

  • dtype (data-type, optional) -- Data-type of the resulting array. Default is the default floating point data type for the device where the returned array is allocated. A structured data-type is not supported.

  • device ({None, string, SyclDevice, SyclQueue}, optional) -- An array API concept of device where the output array is created. The device can be None (the default), an OneAPI filter selector string, an instance of dpctl.SyclDevice corresponding to a non-partitioned SYCL device, an instance of dpctl.SyclQueue, or a Device object returned by dpnp.dpnp_array.dpnp_array.device property.

  • usm_type ({None, "device", "shared", "host"}, optional) -- The type of SYCL USM allocation for the output array. Default is "device".

  • sycl_queue ({None, SyclQueue}, optional) -- A SYCL queue to use for output array allocation and copying.

Returns:

out -- Data read from the text file.

Return type:

dpnp.ndarray

Limitations

Parameter like is supported only with default value None. Otherwise, the function raises NotImplementedError exception.

Notes

This uses numpy.loadtxt and coerces the result to a DPNP array.

See also

dpnp.frombuffer

Construct array from the buffer data.

dpnp.fromstring

Construct array from the text data in a string.

dpnp.fromregex

Construct an array from a text file, using regular expression parsing.

dpnp.load

Load arrays or pickled objects from files.

dpnp.genfromtxt

Load data with missing values handled as specified.

Examples

>>> import dpnp 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.]])

Creating an array on a different device or with a specified usm_type

>>> c = StringIO("0 1\n2 3")
>>> x = np.loadtxt(c, dtype=np.int32) # default case
>>> x.device, x.usm_type
(Device(level_zero:gpu:0), 'device')
>>> c = StringIO("0 1\n2 3")
>>> y = np.loadtxt(c, dtype=np.int32, device='cpu')
>>> y.device, y.usm_type
(Device(opencl:cpu:0), 'device')
>>> c = StringIO("0 1\n2 3")
>>> z = np.loadtxt(c, dtype=np.int32, usm_type="host")
>>> z.device, z.usm_type
(Device(level_zero:gpu:0), 'host')