本文簡要介紹 python 語言中 numpy.heaviside
的用法。
用法:
numpy.heaviside(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True [, signature, extobj ]) = <ufunc 'heaviside'>
計算 Heaviside 階躍函數。
Heaviside 階躍函數定義為:
0 if x1 < 0 heaviside(x1, x2) = x2 if x1 == 0 1 if x1 > 0
其中 x2 通常取 0.5,但有時也使用 0 和 1。
- x1: array_like
輸入值。
- x2: array_like
x1 為 0 時的函數值。如果
x1.shape != x2.shape
,它們必須可以廣播到一個通用形狀(成為輸出的形狀)。- out: ndarray,None,或 ndarray 和 None 的元組,可選
存儲結果的位置。如果提供,它必須具有輸入廣播到的形狀。如果未提供或 None,則返回一個新分配的數組。元組(隻能作為關鍵字參數)的長度必須等於輸出的數量。
- where: 數組,可選
此條件通過輸入廣播。在條件為真的位置,out數組將設置為 ufunc 結果。在其他地方,out數組將保留其原始值。請注意,如果未初始化out數組是通過默認創建的
out=None
,其中條件為 False 的位置將保持未初始化狀態。- **kwargs:
對於其他僅關鍵字參數,請參閱 ufunc 文檔。
- out: ndarray 或標量
x1 的輸出數組、元素級 Heaviside 階躍函數。如果 x1 和 x2 都是標量,則這是一個標量。
參數:
返回:
注意:
參考:
例子:
>>> np.heaviside([-1.5, 0, 2.0], 0.5) array([ 0. , 0.5, 1. ]) >>> np.heaviside([-1.5, 0, 2.0], 1) array([ 0., 1., 1.])
相關用法
- Python numpy hermite.hermfromroots用法及代碼示例
- Python numpy hermite_e.hermediv用法及代碼示例
- Python numpy hermite.hermline用法及代碼示例
- Python numpy hermite.hermpow用法及代碼示例
- Python numpy hermite.hermx用法及代碼示例
- Python numpy hermite_e.hermefromroots用法及代碼示例
- Python numpy hermite.hermmul用法及代碼示例
- Python numpy hermite.herm2poly用法及代碼示例
- Python numpy hermite.hermsub用法及代碼示例
- Python numpy hermite_e.hermeline用法及代碼示例
- Python numpy hermite_e.hermeint用法及代碼示例
- Python numpy hermite_e.hermeadd用法及代碼示例
- Python numpy hermite_e.poly2herme用法及代碼示例
- Python numpy hermite.hermdiv用法及代碼示例
- Python numpy hermite_e.hermevander用法及代碼示例
- Python numpy hermite_e.hermepow用法及代碼示例
- Python numpy hermite.poly2herm用法及代碼示例
- Python numpy hermite_e.hermetrim用法及代碼示例
- Python numpy hermite_e.hermezero用法及代碼示例
- Python numpy hermite.hermdomain用法及代碼示例
- Python numpy hermite_e.hermex用法及代碼示例
- Python numpy hermite.hermadd用法及代碼示例
- Python numpy hermite_e.hermemulx用法及代碼示例
- Python numpy hermite_e.hermeone用法及代碼示例
- Python numpy hermite_e.hermeval用法及代碼示例
注:本文由純淨天空篩選整理自numpy.org大神的英文原創作品 numpy.heaviside。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。