mindspore.numpy.ones

View Source On Gitee
mindspore.numpy.ones(shape, dtype=mstype.float32)[source]

Returns a new tensor of given shape and type, filled with ones.

Parameters
  • shape (Union[int, tuple, list]) – the shape of the new tensor.

  • dtype (Union[mindspore.dtype, str], optional) – Designated tensor dtype. Default is mstype.float32.

Returns

Tensor, with the designated shape and dtype, filled with ones.

Raises
  • TypeError – If input arguments have types not specified above.

  • ValueError – If shape entries have values \(< 0\).

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore.numpy as np
>>> print(np.ones((2,2)))
[[1. 1.]
[1. 1.]]