ones_like

Contents

ones_like#

class brainunit.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 (saiunit.Quantity | Array | ndarray | bool | number | bool | int | float | complex) – The shape and data-type of a define these same attributes of the returned array.

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

  • shape (int | Sequence[int]) – 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:

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")