xarray.indexes.RangeIndex.arange#

classmethod RangeIndex.arange(start=None, stop=None, step=None, *, coord_name=None, dim, dtype=None)[source]#

Create a new RangeIndex from given start, stop and step values.

RangeIndex.arange can be called with a varying number of positional arguments:

  • RangeIndex.arange(stop): the index is within the half-open interval [0, stop) (in other words, the interval including start but excluding stop).

  • RangeIndex.arange(start, stop): the index is within the half-open interval [start, stop).

  • RangeIndex.arange(start, stop, step): the index is within the half-open interval [start, stop), with spacing between values given by step.

Note

When using a non-integer step, such as 0.1, it is often better to use linspace().

Note

RangeIndex.arange(start=4.0) returns a range index in the [0.0, 4.0) interval, i.e., start is interpreted as stop even when it is given as a unique keyword argument.

Parameters:
  • start (float, optional) – Start of interval. The interval includes this value. The default start value is 0. If stop is not given, the value given here is interpreted as the end of the interval.

  • stop (float) – End of interval. In general the interval does not include this value, except floating point round-off affects the size of the dimension.

  • step (float, optional) – Spacing between values (default: 1.0).

  • coord_name (Hashable, optional) – Name of the (lazy) coordinate variable that will be created and associated with the new index. If None, 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.arange(0.0, 1.0, 0.2, 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.2 0.4 0.6 0.8
Data variables:
    *empty*
Indexes:
    x        RangeIndex (start=0, stop=1, step=0.2)