AxisError#
- exception scikitplot.exceptions.AxisError(axis, ndim=None, msg_prefix=None)[source]#
Axis supplied was invalid.
This is raised whenever an
axisparameter is specified that is larger than the number of array dimensions. For compatibility with code written against older numpy versions, which raised a mixture ofValueErrorandIndexErrorfor this situation, this exception subclasses both to ensure thatexcept ValueErrorandexcept IndexErrorstatements continue to catchAxisError.- Parameters:
- axisint or str
The out-of-bounds axis, or a custom exception message string. When a custom message is supplied,
ndimmust be omitted (orNone) andmsg_prefixmust beNone.- ndimint, optional
The number of array dimensions. Required when
axisis an int.- msg_prefixstr, optional
A prefix prepended to the auto-generated message, separated by
": ".
- Attributes:
- axisint or None
The out-of-bounds axis, or
Nonefor the single-argument form.- ndimint or None
The number of array dimensions, or
Nonefor the single-argument form.
Notes
Added in version 1.22: The
axisandndimattributes.The
__slots__declaration prevents creation of a__dict__, keeping instances lightweight.Examples
>>> import numpy as np >>> array_1d = np.arange(10) >>> np.cumsum(array_1d, axis=1) Traceback (most recent call last): ... numpy.exceptions.AxisError: axis 1 is out of bounds for array of dimension 1
Negative axes are preserved:
>>> np.cumsum(array_1d, axis=-2) Traceback (most recent call last): ... numpy.exceptions.AxisError: axis -2 is out of bounds for array of dimension 1
The class constructor generally takes the axis and arrays’ dimensionality as arguments:
>>> print(np.exceptions.AxisError(2, 1, msg_prefix='error')) error: axis 2 is out of bounds for array of dimension 1
Alternatively, a custom exception message can be passed:
>>> print(np.exceptions.AxisError('Custom error message')) Custom error message
- Annotation:
Unrecognized objtype:
exception