Array API compatible wrapper for :py:func:`np.ones `. See its docstring for more information.
(
shape: Union[int, Tuple[int, ...]],
*,
dtype: Optional[Dtype] = None,
device: Optional[Device] = None,
)
| 254 | |
| 255 | |
| 256 | def ones( |
| 257 | shape: Union[int, Tuple[int, ...]], |
| 258 | *, |
| 259 | dtype: Optional[Dtype] = None, |
| 260 | device: Optional[Device] = None, |
| 261 | ) -> Array: |
| 262 | """ |
| 263 | Array API compatible wrapper for :py:func:`np.ones <numpy.ones>`. |
| 264 | |
| 265 | See its docstring for more information. |
| 266 | """ |
| 267 | from ._array_object import Array |
| 268 | |
| 269 | _check_valid_dtype(dtype) |
| 270 | if device not in ["cpu", None]: |
| 271 | raise ValueError(f"Unsupported device {device!r}") |
| 272 | return Array._new(np.ones(shape, dtype=dtype)) |
| 273 | |
| 274 | |
| 275 | def ones_like( |