本文簡要介紹 python 語言中 numpy.multiply
的用法。
用法:
numpy.multiply(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True [, signature, extobj ]) = <ufunc 'multiply'>
逐個元素地乘以參數。
- x1, x2: array_like
要相乘的輸入數組。如果
x1.shape != x2.shape
,它們必須可以廣播到一個公共形狀(成為輸出的形狀)。- out: ndarray,None,或 ndarray 和 None 的元組,可選
存儲結果的位置。如果提供,它必須具有輸入廣播到的形狀。如果未提供或 None,則返回一個新分配的數組。元組(隻能作為關鍵字參數)的長度必須等於輸出的數量。
- where: 數組,可選
此條件通過輸入廣播。在條件為真的位置,out數組將設置為 ufunc 結果。在其他地方,out數組將保留其原始值。請注意,如果未初始化out數組是通過默認創建的
out=None
,其中條件為 False 的位置將保持未初始化狀態。- **kwargs:
對於其他僅關鍵字參數,請參閱 ufunc 文檔。
- y: ndarray
x1 和 x2 的乘積,逐元素。如果 x1 和 x2 都是標量,則這是一個標量。
參數:
返回:
注意:
就數組廣播而言,相當於 x1 * x2。
例子:
>>> np.multiply(2.0, 4.0) 8.0
>>> x1 = np.arange(9.0).reshape((3, 3)) >>> x2 = np.arange(3.0) >>> np.multiply(x1, x2) array([[ 0., 1., 4.], [ 0., 4., 10.], [ 0., 7., 16.]])
*
運算符可用作 ndarray 上np.multiply
的簡寫。>>> x1 = np.arange(9.0).reshape((3, 3)) >>> x2 = np.arange(3.0) >>> x1 * x2 array([[ 0., 1., 4.], [ 0., 4., 10.], [ 0., 7., 16.]])
相關用法
- Python numpy ma.indices用法及代碼示例
- Python numpy matrix.A1用法及代碼示例
- Python numpy ma.zeros用法及代碼示例
- Python numpy matrix.T用法及代碼示例
- Python numpy matrix.I用法及代碼示例
- Python numpy ma.diff用法及代碼示例
- Python numpy mat用法及代碼示例
- Python numpy ma.mask_rowcols用法及代碼示例
- Python numpy ma.where用法及代碼示例
- Python numpy ma.zeros_like用法及代碼示例
- Python numpy mgrid用法及代碼示例
- Python numpy ma.notmasked_contiguous用法及代碼示例
- Python numpy ma.concatenate用法及代碼示例
- Python numpy ma.apply_along_axis用法及代碼示例
- Python numpy matrix.partition用法及代碼示例
- Python numpy ma.compress_rowcols用法及代碼示例
- Python numpy matrix.transpose用法及代碼示例
- Python numpy ma.vstack用法及代碼示例
- Python numpy ma.atleast_3d用法及代碼示例
- Python numpy ma.count用法及代碼示例
- Python numpy matrix.itemsize用法及代碼示例
- Python numpy ma.fix_invalid用法及代碼示例
- Python numpy ma.mean用法及代碼示例
- Python numpy ma.argmax用法及代碼示例
- Python numpy matrix.newbyteorder用法及代碼示例
注:本文由純淨天空篩選整理自numpy.org大神的英文原創作品 numpy.multiply。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。