xarray.indexes.RangeIndex.linspace#
- classmethod RangeIndex.linspace(start, stop, num=50, endpoint=True, *, coord_name=None, dim, dtype=None)[source]#
Create a new RangeIndex from given start / stop values and number of values.
- Parameters:
start (
float
) – Start of interval. The interval includes this value.stop (
float
, optional) – End of interval. The interval includes this value ifendpoint=True
.num (
float
, optional) – Number of values in the interval, i.e., dimension size (default: 50).endpoint (
bool
, optional) – If True (default), thestop
value is included in the interval.coord_name (
Hashable
, optional) – Name of the (lazy) coordinate variable that will be created and associated with the new index. IfNone
, the coordinate is named as the dimension name.dim (
str
) – Dimension name.dtype (
dtype
, optional) – The dtype of the coordinate variable (default: float64).
Examples
>>> from xarray.indexes import RangeIndex
>>> index = RangeIndex.linspace(0.0, 1.0, 5, dim="x") >>> ds = xr.Dataset(coords=xr.Coordinates.from_xindex(index))
>>> ds <xarray.Dataset> Size: 40B Dimensions: (x: 5) Coordinates: * x (x) float64 40B 0.0 0.25 0.5 0.75 1.0 Data variables: *empty* Indexes: x RangeIndex (start=0, stop=1.25, step=0.25)