ones

Contents

ones#

class brainunit.math.ones(shape, dtype=None, unit=Unit('1'))#

Return a new quantity or array of given shape and type, filled with ones.

Parameters:
  • shape (int | Sequence[int]) – Shape of the new quantity or array, e.g., (2, 3) or 2.

  • dtype (str | type[Any] | dtype | SupportsDType | None) – The desired data-type for the array. Default is float.

  • unit (saiunit.Unit) – Unit of the returned Quantity. When UNITLESS (the default) a plain array is returned.

Returns:

out – Array of ones with the given shape and dtype.

Return type:

Array | saiunit.Quantity

Examples

>>> import saiunit as u
>>> u.math.ones((3,))
Array([1., 1., 1.], dtype=float32)
>>> u.math.ones((2, 2), unit=u.meter)
Quantity([[1. 1.]
          [1. 1.]], "m")