本文简要介绍 python 语言中  numpy.AxisError  的用法。
用法:
exception numpy.AxisError(axis, ndim=None, msg_prefix=None)提供的轴无效。
每当一个
axis指定的参数大于数组维数。为了与针对旧 numpy 版本编写的代码兼容,这引发了混合ValueError和IndexError对于这种情况,这个异常子类都确保except ValueError和except IndexError语句继续捕获AxisError.- axis: int 或 str
 越界轴或自定义异常消息。如果提供了轴,则还应指定
ndim。- ndim: 整数,可选
 数组维数。
- msg_prefix: str,可选
 异常消息的前缀。
参数:
例子:
>>> array_1d = np.arange(10) >>> np.cumsum(array_1d, axis=1) Traceback (most recent call last): ... numpy.AxisError: axis 1 is out of bounds for array of dimension 1负轴被保留:
>>> np.cumsum(array_1d, axis=-2) Traceback (most recent call last): ... numpy.AxisError: axis -2 is out of bounds for array of dimension 1类构造函数通常将轴和数组的维度作为参数:
>>> print(np.AxisError(2, 1, msg_prefix='error')) error: axis 2 is out of bounds for array of dimension 1或者,可以传递自定义异常消息:
>>> print(np.AxisError('Custom error message')) Custom error message- axis: 整数,可选
 如果提供了自定义异常消息,则为越界轴或
None。这应该是用户传递的轴,在任何归一化以解决负索引之前。- ndim: 整数,可选
 如果提供了自定义异常消息,则为数组维数或
None。
属性:
相关用法
- Python numpy Arrayterator.flat用法及代码示例
 - Python numpy RandomState.standard_exponential用法及代码示例
 - Python numpy hamming用法及代码示例
 - Python numpy legendre.legint用法及代码示例
 - Python numpy chararray.ndim用法及代码示例
 - Python numpy chebyshev.chebsub用法及代码示例
 - Python numpy chararray.nbytes用法及代码示例
 - Python numpy ma.indices用法及代码示例
 - Python numpy matrix.A1用法及代码示例
 - Python numpy MaskedArray.var用法及代码示例
 - Python numpy ma.zeros用法及代码示例
 - Python numpy broadcast用法及代码示例
 - Python numpy matrix.T用法及代码示例
 - Python numpy matrix.I用法及代码示例
 - Python numpy MaskedArray.T用法及代码示例
 - Python numpy hermite.hermfromroots用法及代码示例
 - Python numpy hermite_e.hermediv用法及代码示例
 - Python numpy recarray.dot用法及代码示例
 - Python numpy random.mtrand.RandomState.wald用法及代码示例
 - Python numpy trim_zeros用法及代码示例
 - Python numpy chebyshev.chebdiv用法及代码示例
 - Python numpy linalg.svd用法及代码示例
 - Python numpy copy用法及代码示例
 - Python numpy negative用法及代码示例
 - Python numpy ndarray.astype用法及代码示例
 
注:本文由纯净天空筛选整理自numpy.org大神的英文原创作品 numpy.AxisError。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
