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 forAxesArray. In such cases a regular numpy array is returned.For functions that are implemented for
AxesArray, such asnp.reshape(), use the numpy function rather than the bound method (e.g.arr.reshape)Such functions may raise
ValueErrorwhere numpy would not, when it is impossible to determine the output axis labels.
Current array function implementations:
np.concatenatenp.reshapenp.transposenp.linalg.solvenp.einsumnp.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 propertiesarr.ax_linenoandarr.n_lineno. IfNoneornp.newaxisare 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
Create the constructor axes dict from this array, with new axis/axes
Create the constructor axes dict from this array, without axis/axes
Attributes
axesShape 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.