本文簡要介紹 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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。