NumPy 的 fmod(~)
方法在給定兩個數組的情況下按元素計算餘數。
注意
mod(~)
與 NumPy 的 fmod(~)
的區別不在於它是否用於浮點數;而在於它是否用於浮點數。它們都能夠解析浮點數。決定性的區別在於它們如何處理負數 - 請查看下麵的示例以進行澄清。
參數
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 = [3, 8, -7]
np.fmod(x, 3)
array([ 0, 2, -1])
在這裏,請注意 fmod(-7,3)=-1
,它與 Python 的標準 % 行為不同,後者為您提供 -7%3=2
。事實上,NumPy 的 fmod(~)
方法遵循主 C 庫的 fmod(~)
實現。
逐元素除法
x = [5, 8]
np.mod(x, [2,3])
array([1, 2])
在這裏,我們隻是執行 5%2=1
和 8%3=2
。
相關用法
- Python fmod()用法及代碼示例
- Python NumPy fliplr方法用法及代碼示例
- Python dict fromkeys()用法及代碼示例
- Python frexp()用法及代碼示例
- Python BeautifulSoup find_next方法用法及代碼示例
- Python functools.wraps用法及代碼示例
- Python NumPy floor方法用法及代碼示例
- Python functools.singledispatchmethod用法及代碼示例
- Python float轉exponential用法及代碼示例
- Python calendar firstweekday()用法及代碼示例
- Python NumPy full方法用法及代碼示例
- Python NumPy flatten方法用法及代碼示例
- Python float.is_integer用法及代碼示例
- Python Django format_lazy用法及代碼示例
- Python format()用法及代碼示例
- Python NumPy fill_diagonal方法用法及代碼示例
- Python filecmp.cmpfiles()用法及代碼示例
- Python functools.singledispatch用法及代碼示例
- Python fileinput.filelineno()用法及代碼示例
- Python NumPy finfo方法用法及代碼示例
- Python BeautifulSoup find_all_next方法用法及代碼示例
- Python fileinput.lineno()用法及代碼示例
- Python fileinput.input用法及代碼示例
- Python functools.partial用法及代碼示例
注:本文由純淨天空篩選整理自Isshin Inada大神的英文原創作品 NumPy | fmod method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。