本文簡要介紹 python 語言中 numpy.ufunc.outer
的用法。
用法:
ufunc.outer(A, B, /, **kwargs)
將 ufunc 操作應用於所有對 (a, b),其中 a 在 A 中,b 在 B 中。
讓
M = A.ndim
,N = B.ndim
.那麽結果,C, 的op.outer(A, B)
是一個維度為 M + N 的數組,使得:對於 A 和 B 一維,這相當於:
r = empty(len(A),len(B)) for i in range(len(A)): for j in range(len(B)): r[i,j] = op(A[i], B[j]) # op = ufunc in question
- A: array_like
第一個數組
- B: array_like
第二個數組
- kwargs: 任何
傳遞給 ufunc 的參數。通常numpy.dtype或者out.看
ufunc
有關所有可用參數的全麵概述。
- r: ndarray
輸出數組
參數:
返回:
例子:
>>> np.multiply.outer([1, 2, 3], [4, 5, 6]) array([[ 4, 5, 6], [ 8, 10, 12], [12, 15, 18]])
多維示例:
>>> A = np.array([[1, 2, 3], [4, 5, 6]]) >>> A.shape (2, 3) >>> B = np.array([[1, 2, 3, 4]]) >>> B.shape (1, 4) >>> C = np.multiply.outer(A, B) >>> C.shape; C (2, 3, 1, 4) array([[[[ 1, 2, 3, 4]], [[ 2, 4, 6, 8]], [[ 3, 6, 9, 12]]], [[[ 4, 8, 12, 16]], [[ 5, 10, 15, 20]], [[ 6, 12, 18, 24]]]])
相關用法
- Python numpy ufunc.at用法及代碼示例
- Python numpy ufunc.ntypes用法及代碼示例
- Python numpy ufunc.identity用法及代碼示例
- Python numpy ufunc.reduce用法及代碼示例
- Python numpy ufunc.nin用法及代碼示例
- Python numpy ufunc.nout用法及代碼示例
- Python numpy ufunc.reduceat用法及代碼示例
- Python numpy ufunc.nargs用法及代碼示例
- Python numpy ufunc.types用法及代碼示例
- Python numpy ufunc.signature用法及代碼示例
- Python numpy ufunc.accumulate用法及代碼示例
- Python numpy union1d用法及代碼示例
- Python numpy unpackbits用法及代碼示例
- Python numpy unravel_index用法及代碼示例
- Python numpy unique用法及代碼示例
- Python numpy unwrap用法及代碼示例
- 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用法及代碼示例
注:本文由純淨天空篩選整理自numpy.org大神的英文原創作品 numpy.ufunc.outer。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。