dpnp.linspace¶
- dpnp.linspace(start, stop, /, num, *, dtype=None, device=None, usm_type=None, sycl_queue=None, endpoint=True, retstep=False, axis=0)[source]¶
Return evenly spaced numbers over a specified interval.
For full documentation refer to
numpy.linspace.- Parameters:
- startarray_like
The starting value of the sequence, in any form that can be converted to an array. This includes scalars, lists, lists of tuples, tuples, tuples of tuples, tuples of lists, and ndarrays.
- stoparray_like
The end value of the sequence, in any form that can be converted to an array. This includes scalars, lists, lists of tuples, tuples, tuples of tuples, tuples of lists, and ndarrays. If endpoint is set to
Falsethe sequence consists of all but the last ofnum + 1evenly spaced samples, so that stop is excluded.- numint
Number of samples. Must have a nonnegative value.
- dtype{None, str, dtype object}, optional
The desired dtype for the array. If not given, a default dtype will be used that can represent the values (by considering Promotion Type Rule and device capabilities when necessary).
Default:
None.- 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:
None.- sycl_queue{None, SyclQueue}, optional
A SYCL queue to use for output array allocation and copying.
Default:
None.- endpointbool, optional
If
True, stop is the last sample. Otherwise, it is not included.Default:
True.- retstepbool, optional
If
True, return (samples, step), where step is the spacing between samples.Default:
False.- axisint, optional
The axis in the result to store the samples. Relevant only if start or stop are array-like. By default (0), the samples will be along a new axis inserted at the beginning. Use -1 to get an axis at the end.
Default:
0.
- Returns:
- outdpnp.ndarray
There are num equally spaced samples in the closed interval [start, stop] or the half-open interval [start, stop) (depending on whether endpoint is
TrueorFalse).- stepfloat, optional
Only returned if retstep is
True. Size of spacing between samples.
See also
dpnp.arangeSimilar to
dpnp.linspace, but uses a step size (instead of the number of samples).dpnp.geomspaceSimilar to
dpnp.linspace, but with numbers spaced evenly on a log scale (a geometric progression).dpnp.logspaceSimilar to
dpnp.geomspace, but with the end points specified as logarithms.
Examples
>>> import dpnp as np >>> np.linspace(2.0, 3.0, num=5) array([2. , 2.25, 2.5 , 2.75, 3. ])
>>> np.linspace(2.0, 3.0, num=5, endpoint=False) array([2. , 2.2, 2.4, 2.6, 2.8])
>>> np.linspace(2.0, 3.0, num=5, retstep=True) (array([2. , 2.25, 2.5 , 2.75, 3. ]), array(0.25))
Creating an array on a different device or with a specified usm_type
>>> x = np.linspace(2.0, 3.0, num=3) # default case >>> x, x.device, x.usm_type (array([2. , 2.5, 3. ]), Device(level_zero:gpu:0), 'device')
>>> y = np.linspace(2.0, 3.0, num=3, device="cpu") >>> y, y.device, y.usm_type (array([2. , 2.5, 3. ]), Device(opencl:cpu:0), 'device')
>>> z = np.linspace(2.0, 3.0, num=3, usm_type="host") >>> z, z.device, z.usm_type (array([2. , 2.5, 3. ]), Device(level_zero:gpu:0), 'host')