ones_like

Contents

ones_like#

class saiunit.math.ones_like(a, dtype=None, shape=None, unit=Unit('1'))#

Return a quantity or array of ones with the same shape and type as a given array.

Parameters:
  • a (Union[saiunit.Quantity, Array, ndarray, number, bool]) – The shape and data-type of a define these same attributes of the returned array.

  • dtype (Union[str, type[Any], dtype, SupportsDType, None]) – Overrides the data type of the result.

  • shape (Union[int, Sequence[int], None]) – Overrides the shape of the result. If not given, a.shape is used.

  • unit (saiunit.Unit) – Unit of the returned Quantity.

Returns:

out – Array of ones with the same shape and type as a.

Return type:

Union[saiunit.Quantity, Array]

Examples

>>> import saiunit as u
>>> import jax.numpy as jnp
>>> u.math.ones_like(jnp.array([1.0, 2.0, 3.0]))
Array([1., 1., 1.], dtype=float32)
>>> u.math.ones_like(jnp.array([1.0, 2.0]) * u.meter)
Quantity([1. 1.], "m")