dpnp.ones

dpnp.ones(shape, *, dtype=None, order='C', like=None, device=None, usm_type='device', sycl_queue=None)[source]

Return a new array of given shape and type, filled with ones.

For full documentation refer to numpy.ones.

Parameters:
  • shape ({int, sequence of ints}) -- Shape of the new array, e.g., (2, 3) or 2.

  • dtype ({None, dtype}, optional) -- The desired dtype for the array, e.g., dpnp.int32. Default is the default floating point data type for the device where input array is allocated.

  • order ({"C", "F", None}, optional) -- Memory layout of the newly output array. Default: "C".

  • 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 -- Array of ones with the given shape, dtype, and order.

Return type:

dpnp.ndarray

Limitations

Parameter order is supported only with values "C", "F" and None. Parameter like is supported only with default value None. Otherwise, the function raises NotImplementedError exception.

See also

dpnp.ones_like

Return an array of ones with shape and type of input.

dpnp.empty

Return a new uninitialized array.

dpnp.zeros

Return a new array setting values to zero.

dpnp.full

Return a new array of given shape filled with value.

Examples

>>> import dpnp as np
>>> np.ones(5)
array([1., 1., 1., 1., 1.])
>>> x = np.ones((2, 1))
>>> x.ndim, x.size, x.shape
(2, 2, (2, 1))
>>> x
array([[1.],
       [1.]])

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

>>> x = np.ones(3) # default case
>>> x, x.device, x.usm_type
(array([1., 1., 1.]), Device(level_zero:gpu:0), 'device')
>>> y = np.ones(3, device="cpu")
>>> y, y.device, y.usm_type
(array([1., 1., 1.]), Device(opencl:cpu:0), 'device')
>>> z = np.ones(3, usm_type="host")
>>> z, z.device, z.usm_type
(array([1., 1., 1.]), Device(level_zero:gpu:0), 'host')