scipp.ones#
- scipp.ones(*, dims=None, shape=None, sizes=None, unit=<automatically deduced unit>, dtype=DType('float64'), with_variances=False)#
Constructs a
Variable
with values initialized to 1 with given dimension labels and shape.The dims and shape can also be specified using a sizes dict.
- Parameters:
dims (
Optional
[Sequence
[str
]], default:None
) – Optional (if sizes is specified), dimension labels.shape (
Optional
[Sequence
[int
]], default:None
) – Optional (if sizes is specified), dimension sizes.sizes (
Optional
[dict
[str
,int
]], default:None
) – Optional, dimension label to size map.unit (
Unit
|str
|DefaultUnit
|None
, default:<automatically deduced unit>
) – Unit of contents.dtype (
scipp.typing.DTypeLike
) – Type of underlying data.with_variances (
bool
, default:False
) – If True includes variances initialized to 1.
- Returns:
Variable
– A variable filled with 1’s.
See also
scipp.array
,scipp.empty
,scipp.ones_like
,scipp.scalar
,scipp.zeros
Examples
>>> sc.ones(dims=['x'], shape=[4]) <scipp.Variable> (x: 4) float64 [dimensionless] [1, 1, 1, 1]
>>> sc.ones(sizes={'x': 4}) <scipp.Variable> (x: 4) float64 [dimensionless] [1, 1, 1, 1]
>>> sc.ones(sizes={'y': 3}, with_variances=True) <scipp.Variable> (y: 3) float64 [dimensionless] [1, 1, 1] [1, 1, 1]
>>> sc.ones(sizes={'z': 3}, unit='kg', dtype=int) <scipp.Variable> (z: 3) int64 [kg] [1, 1, 1]