class xarray.Variable(dims, data, attrs=None, encoding=None, fastpath=False)

A netcdf-like variable consisting of dimensions, data and attributes which describe a single Array. A single Variable object is not fully described outside the context of its parent Dataset (if you want such a fully described object, use a DataArray instead).

The main functional difference between Variables and numpy arrays is that numerical operations on Variables implement array broadcasting by dimension name. For example, adding an Variable with dimensions (‘time’,) to another Variable with dimensions (‘space’,) results in a new Variable with dimensions (‘time’, ‘space’). Furthermore, numpy reduce operations like mean or sum are overwritten to take a “dimension” argument instead of an “axis”.

Variables are light-weight objects used as the building block for datasets. They are more primitive objects, so operations with them provide marginally higher performance than using DataArrays. However, manipulating data in the form of a Dataset or DataArray should almost always be preferred, because they can use more complete metadata in context of coordinate labels.

__init__(dims, data, attrs=None, encoding=None, fastpath=False)

dims : str or sequence of str

Name(s) of the the data dimension(s). Must be either a string (only for 1D data) or a sequence of strings with length equal to the number of dimensions.

data : array_like

Data array which supports numpy-like data access.

attrs : dict_like or None, optional

Attributes to assign to the new variable. If None (default), an empty attribute dictionary is initialized.

encoding : dict_like or None, optional

Dictionary specifying how to encode this array’s data into a serialized format like netCDF4. Currently used keys (for netCDF) include ‘_FillValue’, ‘scale_factor’, ‘add_offset’ and ‘dtype’. Well-behaved code to serialize a Variable should ignore unrecognized encoding items.


__init__(dims, data[, attrs, encoding, fastpath])
all([dim, axis, keep_attrs]) Reduce this Variable’s data by applying all along some dimension(s).
any([dim, axis, keep_attrs]) Reduce this Variable’s data by applying any along some dimension(s).
argmax([dim, axis, skipna, keep_attrs]) Reduce this Variable’s data by applying argmax along some dimension(s).
argmin([dim, axis, skipna, keep_attrs]) Reduce this Variable’s data by applying argmin along some dimension(s).
argsort([axis, kind, order]) Returns the indices that would sort this array.
astype(dtype[, order, casting, subok, copy]) Copy of the array, cast to a specified type.
broadcast_equals(other) True if two Variables have the values after being broadcast against each other; otherwise False.
chunk([chunks, name, lock]) Coerce this array’s data into a dask arrays with the given chunks.
clip([min, max, out]) Return an array whose values are limited to [min, max].
concat(variables[, dim, positions, shortcut]) Concatenate variables along a new or existing dimension.
conj() Complex-conjugate all elements.
conjugate() Return the complex conjugate, element-wise.
copy([deep]) Returns a copy of this object.
count([dim, axis, keep_attrs]) Reduce this Variable’s data by applying count along some dimension(s).
equals(other) True if two Variables have the same dimensions and values; otherwise False.
expand_dims(dims[, shape]) Return a new variable with expanded dimensions.
get_axis_num(dim) Return axis number(s) corresponding to dimension(s) in this array.
identical(other) Like equals, but also checks attributes.
isel(**indexers) Return a new array indexed along the specified dimension(s).
isnull(*args, **kwargs) Detect missing values (NaN in numeric arrays, None/NaN in object arrays)
item(*args) Copy an element of an array to a standard Python scalar and return it.
load() Manually trigger loading of this variable’s data from disk or a remote source into memory and return this variable.
max([dim, axis, skipna, keep_attrs]) Reduce this Variable’s data by applying max along some dimension(s).
mean([dim, axis, skipna, keep_attrs]) Reduce this Variable’s data by applying mean along some dimension(s).
median([dim, axis, skipna, keep_attrs]) Reduce this Variable’s data by applying median along some dimension(s).
min([dim, axis, skipna, keep_attrs]) Reduce this Variable’s data by applying min along some dimension(s).
notnull(*args, **kwargs) Replacement for numpy.isfinite / -numpy.isnan which is suitable for use on object arrays.
prod([dim, axis, skipna, keep_attrs]) Reduce this Variable’s data by applying prod along some dimension(s).
reduce(func[, dim, axis, keep_attrs, allow_lazy]) Reduce this array by applying func along some dimension(s).
roll(**shifts) Return a new Variable with rolld data.
round(*args, **kwargs)
searchsorted(v[, side, sorter]) Find indices where elements of v should be inserted in a to maintain order.
shift(**shifts) Return a new Variable with shifted data.
squeeze([dim]) Return a new Variable object with squeezed data.
stack(**dimensions) Stack any number of existing dimensions into a single new dimension.
std([dim, axis, skipna, keep_attrs]) Reduce this Variable’s data by applying std along some dimension(s).
sum([dim, axis, skipna, keep_attrs]) Reduce this Variable’s data by applying sum along some dimension(s).
to_coord() Return this variable as an xarray.Coordinate
to_index() Convert this variable to a pandas.Index
to_variable() Return this variable as a base xarray.Variable
transpose(*dims) Return a new Variable object with transposed dimensions.
unstack(**dimensions) Unstack an existing dimension into multiple new dimensions.
var([dim, axis, skipna, keep_attrs]) Reduce this Variable’s data by applying var along some dimension(s).


attrs Dictionary of local attributes on this variable.
chunks Block dimensions for this array’s data or None if it’s not a dask array.
dims Tuple of dimension names with which this variable is associated.
encoding Dictionary of encodings on this variable.
values The variable’s data as a numpy.ndarray