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:
  • start (array_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.

  • stop (array_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 False the sequence consists of all but the last of num + 1 evenly spaced samples, so that stop is excluded.

  • dtype ({None, dtype}, 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).

  • 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: None.

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

  • endpoint (bool, optional) -- If True, stop is the last sample. Otherwise, it is not included. Default: True.

  • retstep (bool, optional) -- If True, return (samples, step), where step is the spacing between samples.

  • axis (int, 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.

Returns:

  • out (dpnp.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 True or False).

  • step (float, optional) -- Only returned if retstep is True. Size of spacing between samples.

See also

dpnp.arange

Similar to dpnp.linspace, but uses a step size (instead of the number of samples).

dpnp.geomspace

Similar to dpnp.linspace, but with numbers spaced evenly on a log scale (a geometric progression).

dpnp.logspace

Similar 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')