Utils

sklearn_xarray.utils

convert_to_ndarray(X, new_dim_last=True, new_dim_name='variable')[source]

Convert xarray DataArray or Dataset to numpy ndarray.

Parameters
Xxarray DataArray or Dataset

The input data.

new_dim_lastbool, default true

If true, put the new dimension last when converting a Dataset with multiple variables.

new_dim_namestr, default ‘variable’

The name of the new dimension when converting a Dataset with multiple variables.

Returns
X_arrnumpy ndarray

The data as an ndarray.

get_group_indices(X, groupby, group_dim=None)[source]

Get logical index vectors for each group.

Parameters
Xxarray DataArray or Dataset

The data structure for which to determine the indices.

groupbystr or list

Name of coordinate or list of coordinates by which the groups are determined.

group_dimstr or None, optional

Name of dimension along which the groups are indexed.

Returns
idx: list of boolean numpy vectors

List of logical indices for each group.

is_dataarray(X, require_attrs=None)[source]

Check whether an object is a DataArray.

Parameters
Xanything

The object to be checked.

require_attrslist of str, optional

The attributes the object has to have in order to pass as a DataArray.

Returns
bool

Whether the object is a DataArray or not.

is_dataset(X, require_attrs=None)[source]

Check whether an object is a Dataset.

Parameters
Xanything

The object to be checked.

require_attrslist of str, optional

The attributes the object has to have in order to pass as a Dataset.

Returns
bool

Whether the object is a Dataset or not.

is_target(X, require_attrs=None)[source]

Check whether an object is a Target.

Parameters
Xanything

The object to be checked.

require_attrslist of str, optional

The attributes the object has to have in order to pass as a Target.

Returns
bool

Whether the object is a Target or not.

segment_array(arr, axis, new_len, step=1, new_axis=None, return_view=False)[source]

Segment an array along some axis.

Parameters
arrarray-like

The input array.

axisint

The axis along which to segment.

new_lenint

The length of each segment.

stepint, default 1

The offset between the start of each segment.

new_axisint, optional

The position where the newly created axis is to be inserted. By default, the axis will be added at the end of the array.

return_viewbool, default False

If True, return a view of the segmented array instead of a copy.

Returns
arr_segarray-like

The segmented array.