spectrochempy.ones
- ones(shape, dtype=None, **kwargs)[source]
Return a new
NDDataset
of given shape and type, filled with ones.- Parameters:
shape (int or sequence of ints) – Shape of the new array, e.g.,
(2, 3)
or2
.dtype (data-type, optional) – The desired data-type for the array, e.g.,
numpy.int8
. Default is**kwargs – Optional keyword parameters (see Other Parameters).
- Returns:
ones – Array of
ones
.- Other Parameters:
units (str or ur instance) – Units of the returned object. If not provided, try to copy from the input object.
coordset (list or Coordset object) – Coordinates for the returned object. If not provided, try to copy from the input object.
See also
zeros_like
Return an array of zeros with shape and type of input.
ones_like
Return an array of ones with shape and type of input.
empty_like
Return an empty array with shape and type of input.
full_like
Fill an array with shape and type of input.
zeros
Return a new array setting values to zero.
empty
Return a new uninitialized array.
full
Fill a new array.
Examples
>>> nd = scp.ones(5, units='km') >>> nd NDDataset: [float64] km (size: 5) >>> nd.values <Quantity([ 1 1 1 1 1], 'kilometer')> >>> nd = scp.ones((5,), dtype=np.int, mask=[True, False, False, False, True]) >>> nd NDDataset: [int64] unitless (size: 5) >>> nd.values masked_array(data=[ --, 1, 1, 1, --], mask=[ True, False, False, False, True], fill_value=999999) >>> nd = scp.ones((5,), dtype=np.int, mask=[True, False, False, False, True], units='joule') >>> nd NDDataset: [int64] J (size: 5) >>> nd.values <Quantity([ -- 1 1 1 --], 'joule')> >>> scp.ones((2, 2)).values array([[ 1, 1], [ 1, 1]])