Numpy 的 divide(~)
方法在給定兩個數組的情況下執行逐元素真除法。真正的除法意味著 5/2=2.5
而不是樓層除法,即 5//2=2
。
方法divide(~)
和 true_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.divide(x, 2)
array([1. , 3. , 4.5])
除以多個除數
x = [2,6,9]
np.divide(x, [2,3,4])
array([1. , 2. , 2.25])
在這裏,我們正在執行 2/2
、 6/3
和 9/4
。
相關用法
- Python divmod()用法及代碼示例
- Python divmod方法用法及代碼示例
- Python NumPy divmod方法用法及代碼示例
- Python distributed.protocol.serialize.register_generic用法及代碼示例
- Python distributed.get_task_metadata用法及代碼示例
- Python distributed.Client.gather用法及代碼示例
- Python distributed.recreate_tasks.ReplayTaskClient.recreate_task_locally用法及代碼示例
- Python distributed.diagnostics.plugin.SchedulerPlugin用法及代碼示例
- Python distributed.Client.ncores用法及代碼示例
- Python distributed.Client.retire_workers用法及代碼示例
- Python distributed.Client.unregister_worker_plugin用法及代碼示例
- Python distributed.fire_and_forget用法及代碼示例
- Python dir用法及代碼示例
- Python distributed.Client.set_metadata用法及代碼示例
- Python dictionary cmp()用法及代碼示例
- Python distributed.Client.scheduler_info用法及代碼示例
- Python distributed.Client.submit用法及代碼示例
- Python distributed.Client.compute用法及代碼示例
- Python distributed.SpecCluster.scale用法及代碼示例
- Python distributed.get_worker用法及代碼示例
- Python distributed.SpecCluster.scale_up用法及代碼示例
- Python difflib.unified_diff用法及代碼示例
- Python distributed.Client.nthreads用法及代碼示例
- Python distributed.comm.resolve_address用法及代碼示例
- Python distributed.Client.unpublish_dataset用法及代碼示例
注:本文由純淨天空篩選整理自Isshin Inada大神的英文原創作品 NumPy | divide method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。