本文簡要介紹 python 語言中 numpy.append
的用法。
用法:
numpy.append(arr, values, axis=None)
將值附加到數組的末尾。
- arr: array_like
值將附加到此數組的副本中。
- values: array_like
這些值附加到 arr 的副本中。它必須具有正確的形狀(與 arr 形狀相同,不包括軸)。如果未指定軸,則值可以是任何形狀,並且在使用前會被展平。
- axis: 整數,可選
附加值的軸。如果未給出軸,則 arr 和 values 在使用前都會被展平。
- append: ndarray
一份arr和值附加到軸.注意
append
不會就地發生:分配並填充一個新數組。如果軸是無,out是一個扁平數組。
參數:
返回:
例子:
>>> np.append([1, 2, 3], [[4, 5, 6], [7, 8, 9]]) array([1, 2, 3, ..., 7, 8, 9])
指定軸時,值必須具有正確的形狀。
>>> np.append([[1, 2, 3], [4, 5, 6]], [[7, 8, 9]], axis=0) array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) >>> np.append([[1, 2, 3], [4, 5, 6]], [7, 8, 9], axis=0) Traceback (most recent call last): ... ValueError: all the input arrays must have same number of dimensions, but the array at index 0 has 2 dimension(s) and the array at index 1 has 1 dimension(s)
相關用法
- Python numpy apply_over_axes用法及代碼示例
- Python numpy apply_along_axis用法及代碼示例
- Python numpy asscalar用法及代碼示例
- Python numpy any用法及代碼示例
- Python numpy ascontiguousarray用法及代碼示例
- Python numpy asarray_chkfinite用法及代碼示例
- Python numpy argpartition用法及代碼示例
- Python numpy arctan用法及代碼示例
- Python numpy array用法及代碼示例
- Python numpy array_repr用法及代碼示例
- Python numpy arccos用法及代碼示例
- Python numpy all用法及代碼示例
- Python numpy add用法及代碼示例
- Python numpy around用法及代碼示例
- Python numpy array2string用法及代碼示例
- Python numpy atleast_1d用法及代碼示例
- Python numpy asanyarray用法及代碼示例
- Python numpy arctan2用法及代碼示例
- Python numpy angle用法及代碼示例
- Python numpy arctanh用法及代碼示例
- Python numpy arccosh用法及代碼示例
- Python numpy arange用法及代碼示例
- Python numpy argsort用法及代碼示例
- Python numpy asarray用法及代碼示例
- Python numpy array_equiv用法及代碼示例
注:本文由純淨天空篩選整理自numpy.org大神的英文原創作品 numpy.append。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。