pysindy.utils.AxesArray

class pysindy.utils.AxesArray(input_array: ndarray[tuple[Any, ...], dtype[_ScalarT]], axes: Dict[str, int | List[int]])[source]

A numpy-like array that keeps track of the meaning of its axes.

Limitations:

  • Not all numpy functions, such as np.flatten(), have an implementation for AxesArray. In such cases a regular numpy array is returned.

  • For functions that are implemented for AxesArray, such as np.reshape(), use the numpy function rather than the bound method (e.g. arr.reshape)

  • Such functions may raise ValueError where numpy would not, when it is impossible to determine the output axis labels.

Current array function implementations:

  • np.concatenate

  • np.reshape

  • np.transpose

  • np.linalg.solve

  • np.einsum

  • np.tensordot

Indexing:

AxesArray supports all of the basic and advanced indexing of numpy arrays, with the addition that new axes can be inserted with a string name for the axis. E.g. arr = arr[..., "lineno"] will add a length-one axis at the end, along with the properties arr.ax_lineno and arr.n_lineno. If None or np.newaxis are passed, the axis is named “unk”.

Parameters:
  • input_array – the data to create the array.

  • axes – A dictionary of axis labels to shape indices. Axes labels must be of the format "ax_name". indices can be either an int or a list of ints.

Attributes:
  • axes – dictionary of axis name to dimension index/indices

  • ax_<ax_name> – lookup ax_name in axes

  • n_<ax_name> – lookup shape of subarray defined by ax_name

Raises:
  • AxesWarning if axes does not match shape of input_array.

  • ValueError if assigning the same axis index to multiple meanings or – assigning an axis beyond ndim.

Methods

insert_axis

Create the constructor axes dict from this array, with new axis/axes

remove_axis

Create the constructor axes dict from this array, without axis/axes

Attributes

axes

shape

Shape of array.

insert_axis(axis: Collection[int] | int, new_name: str) Dict[str, int | List[int]][source]

Create the constructor axes dict from this array, with new axis/axes

remove_axis(axis: Collection[int] | int) Dict[str, int | List[int]][source]

Create the constructor axes dict from this array, without axis/axes

property shape

Shape of array. Unlike numpy ndarray, this is not assignable.