ivy.ones(shape: Iterable[int], dtype_str: str = 'float32', dev_str: Optional[str] = None, f: Optional[ivy.Framework] = None) → Union[ivy.Array, ivy.NativeArray][source]

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

  • shape (sequence of ints) – Shape of the new array, e.g. (2, 3).

  • dtype_str – The desired data-type for the array in string format, i.e. ‘float32’ or ‘int64’.

Default is ‘float32’. :type dtype_str: data-type string, optional :param dev_str: device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc.. :type dev_str: str :param f: Machine learning framework. Inferred from inputs if None. :type f: ml_framework, optional :return: Tensor of ones with the given shape and dtype_str.

Supported Frameworks:

empty jax_logo empty tf_logo empty pytorch_logo empty mxnet_logo empty numpy_logo empty