xarray.ones_like#
- xarray.ones_like(other, dtype=None)[source]#
Return a new object of ones with the same shape and type as a given dataarray or dataset.
- Parameters:
- 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)> array([[0, 1, 2], [3, 4, 5]]) Coordinates: * lat (lat) int64 1 2 * lon (lon) int64 0 1 2
>>> xr.ones_like(x) <xarray.DataArray (lat: 2, lon: 3)> array([[1, 1, 1], [1, 1, 1]]) Coordinates: * lat (lat) int64 1 2 * lon (lon) int64 0 1 2
See also