xarray.ones_like#
- xarray.ones_like(other, dtype=None, *, chunks=None, chunked_array_type=None, from_array_kwargs=None)[source]#
Return a new object of ones with the same shape and type as a given dataarray or dataset.
- Parameters:
other (
DataArray
,Dataset
, orVariable
) β The reference object. The output will have the same dimensions and coordinates as this object.dtype (
dtype
, optional) β dtype of the new array. If omitted, it defaults to other.dtype.chunks (
int
,"auto"
,tuple
ofint
or mapping ofHashable
toint
, optional) β Chunk sizes along each dimension, e.g.,5
,"auto"
,(5, 5)
or{"x": 5, "y": 5}
.chunked_array_type (
str
, optional) β Which chunked array type to coerce the underlying data array to. Defaults to βdaskβ if installed, else whatever is registered via the ChunkManagerEnetryPoint system. Experimental API that should not be relied upon.from_array_kwargs (
dict
, optional) β Additional keyword arguments passed on to the ChunkManagerEntrypoint.from_array method used to create chunked arrays, via whichever chunk manager is specified through the chunked_array_type kwarg. For example, with dask as the default chunked array type, this method would pass additional kwargs todask.array.from_array()
. Experimental API that should not be relied upon.
- Returns:
out (
same as object
) β New object of ones with the same shape and type as other.
Examples
>>> x = xr.DataArray( ... np.arange(6).reshape(2, 3), ... dims=["lat", "lon"], ... coords={"lat": [1, 2], "lon": [0, 1, 2]}, ... ) >>> x <xarray.DataArray (lat: 2, lon: 3)> Size: 48B array([[0, 1, 2], [3, 4, 5]]) Coordinates: * lat (lat) int64 16B 1 2 * lon (lon) int64 24B 0 1 2
>>> xr.ones_like(x) <xarray.DataArray (lat: 2, lon: 3)> Size: 48B array([[1, 1, 1], [1, 1, 1]]) Coordinates: * lat (lat) int64 16B 1 2 * lon (lon) int64 24B 0 1 2
See also