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:
- fnamefile, str, pathlib.Path, list of str, generator
File, filename, list, or generator to read. If the filename extension is
.gzor.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{None, str, dtype object}, optional
Data-type of the resulting array. If
None, uses a default floating point data type for the device on which the returned array is allocated. A structured data-type is not supported.Default:
float.- device{None, string, SyclDevice, SyclQueue, Device}, optional
An array API concept of device where the output array is created. device can be
None, a oneAPI filter selector string, an instance ofdpctl.SyclDevicecorresponding to a non-partitioned SYCL device, an instance ofdpctl.SyclQueue, or adpnp.tensor.Deviceobject returned bydpnp.ndarray.device.Default:
None.- usm_type{None, "device", "shared", "host"}, optional
The type of SYCL USM allocation for the output array.
Default:
"device".- sycl_queue{None, SyclQueue}, optional
A SYCL queue to use for output array allocation and copying. The sycl_queue can be passed as
None(the default), which means to get the SYCL queue from device keyword if present or to use a default queue.Default:
None.
- Returns:
- outdpnp.ndarray
Data read from the text file.
Limitations
Parameter like is supported only with default value
None. Otherwise, the function raisesNotImplementedErrorexception.See also
dpnp.frombufferConstruct array from the buffer data.
dpnp.fromstringConstruct array from the text data in a string.
dpnp.fromregexConstruct an array from a text file, using regular expression parsing.
dpnp.loadLoad arrays or pickled objects from files.
dpnp.genfromtxtLoad data with missing values handled as specified.
Notes
This uses
numpy.loadtxtand coerces the result to a DPNP array.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')