Numpy 的 true_divide(~)
方法在給定兩個數組的情況下執行逐元素真除法。真正的除法意味著 5/2=2.5
而不是樓層除法,即 5//2=2
。
方法true_divide(~)
和 divide(~)
是等效的。
警告
選擇使用 /
運算符
如果您不需要此方法的第三個和第四個參數,隻需使用 /
運算符劃分兩個數組 - 您將享受到性能提升。
參數
1. x1
| array_like
充當被除數的數組。
2. x2
| array_like
充當除數的數組。
3. out
| Numpy array
| optional
您可以將計算結果放入 out
指定的數組中,而不是創建新數組。
4. where
| boolean
的array
| optional
標記為 False 的值將被忽略,即它們的原始值將未被初始化。如果指定了 out 參數,行為會略有不同 - 原始值將保持不變。
返回值
如果 x1
和 x2
是標量,則返回標量,否則返回 Numpy 數組。
例子
除以公約數
x = [2,6,9]
np.true_divide(x, 2)
array([1. , 3. , 4.5])
除以多個除數
x = [2,6,9]
np.true_divide(x, [2,3,4])
array([1. , 2. , 2.25])
在這裏,我們正在執行 2/2
、 6/3
和 9/4
。
相關用法
- Python trunc()用法及代碼示例
- Python NumPy trunc方法用法及代碼示例
- Python NumPy tri方法用法及代碼示例
- Python NumPy trim_zeros方法用法及代碼示例
- Python tracemalloc.Traceback.format用法及代碼示例
- Python NumPy transpose方法用法及代碼示例
- Python torch.distributed.rpc.rpc_async用法及代碼示例
- Python torch.nn.InstanceNorm3d用法及代碼示例
- Python tf.compat.v1.distributions.Multinomial.stddev用法及代碼示例
- Python tf.compat.v1.distribute.MirroredStrategy.experimental_distribute_dataset用法及代碼示例
- Python torchaudio.transforms.Fade用法及代碼示例
- Python tf.compat.v1.data.TFRecordDataset.interleave用法及代碼示例
- Python tf.summary.scalar用法及代碼示例
- Python tf.linalg.LinearOperatorFullMatrix.matvec用法及代碼示例
- Python tf.linalg.LinearOperatorToeplitz.solve用法及代碼示例
- Python tf.raw_ops.TPUReplicatedInput用法及代碼示例
- Python tf.raw_ops.Bitcast用法及代碼示例
- Python tf.compat.v1.distributions.Bernoulli.cross_entropy用法及代碼示例
- Python Pandas tseries.offsets.CustomBusinessHour.onOffset用法及代碼示例
- Python torch.special.gammaincc用法及代碼示例
- Python typing.get_type_hints用法及代碼示例
- Python tensorflow.math.xlog1py()用法及代碼示例
- Python tf.compat.v1.Variable.eval用法及代碼示例
- Python tf.compat.v1.train.FtrlOptimizer.compute_gradients用法及代碼示例
- Python tf.distribute.OneDeviceStrategy.experimental_distribute_values_from_function用法及代碼示例
注:本文由純淨天空篩選整理自Isshin Inada大神的英文原創作品 NumPy | true_divide method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。