ones

ones(shape: int | Tuple[int, ...], *, dtype: dtype | None = None, device: device | None = None) array

Returns a new array having a specified shape and filled with ones.

Note

An output array having a complex floating-point data type must contain complex numbers having a real component equal to one and an imaginary component equal to zero (i.e., 1 + 0j).

Parameters:
  • shape (Union[int, Tuple[int, ...]]) – output array shape.

  • dtype (Optional[dtype]) – output array data type. If dtype is None, the output array data type must be the default real-valued floating-point data type. Default: None.

  • device (Optional[device]) – device on which to place the created array. Default: None.

Returns:

out (array) – an array containing ones.

Notes

Changed in version 2022.12: Added complex data type support.