本文簡要介紹 python 語言中 numpy.right_shift
的用法。
用法:
numpy.right_shift(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True [, signature, extobj ]) = <ufunc 'right_shift'>
將整數的位向右移動。
位向右移動x2。因為數字的內部表示是二進製格式,所以這個運算相當於除法x1經過
2**x2
.- x1: 數組樣,int
輸入值。
- x2: 數組樣,int
右側要刪除的位數x1.如果
x1.shape != x2.shape
,它們必須可以廣播到一個共同的形狀(成為輸出的形狀)。- out: ndarray,None,或 ndarray 和 None 的元組,可選
存儲結果的位置。如果提供,它必須具有輸入廣播到的形狀。如果未提供或 None,則返回一個新分配的數組。元組(隻能作為關鍵字參數)的長度必須等於輸出的數量。
- where: 數組,可選
此條件通過輸入廣播。在條件為真的位置,out數組將設置為 ufunc 結果。在其他地方,out數組將保留其原始值。請注意,如果未初始化out數組是通過默認創建的
out=None
,其中條件為 False 的位置將保持未初始化狀態。- **kwargs:
對於其他僅關鍵字參數,請參閱 ufunc 文檔。
- out: ndarray,int
返回x1位移位x2次向右。如果兩者都是,則這是一個標量x1和x2是標量。
參數:
返回:
例子:
>>> np.binary_repr(10) '1010' >>> np.right_shift(10, 1) 5 >>> np.binary_repr(5) '101'
>>> np.right_shift(10, [1,2,3]) array([5, 2, 1])
>>
運算符可用作 ndarray 上np.right_shift
的簡寫。>>> x1 = 10 >>> x2 = np.array([1,2,3]) >>> x1 >> x2 array([5, 2, 1])
相關用法
- Python numpy rint用法及代碼示例
- Python numpy recarray.dot用法及代碼示例
- Python numpy random.mtrand.RandomState.wald用法及代碼示例
- Python numpy recarray.itemset用法及代碼示例
- Python numpy random.mtrand.RandomState.multivariate_normal用法及代碼示例
- Python numpy random.standard_exponential用法及代碼示例
- Python numpy recarray.view用法及代碼示例
- Python numpy random.mtrand.RandomState.gumbel用法及代碼示例
- Python numpy random.mtrand.RandomState.multinomial用法及代碼示例
- Python numpy random.rand用法及代碼示例
- Python numpy random.mtrand.RandomState.logistic用法及代碼示例
- Python numpy random.mtrand.RandomState.shuffle用法及代碼示例
- Python numpy random.triangular用法及代碼示例
- Python numpy recarray.tolist用法及代碼示例
- Python numpy recarray.setflags用法及代碼示例
- Python numpy random.noncentral_f用法及代碼示例
- Python numpy roll用法及代碼示例
- Python numpy recarray.flat用法及代碼示例
- Python numpy random.mtrand.RandomState.poisson用法及代碼示例
- Python numpy rollaxis用法及代碼示例
- Python numpy recarray用法及代碼示例
- Python numpy recarray.sort用法及代碼示例
- Python numpy random.lognormal用法及代碼示例
- Python numpy random.mtrand.RandomState.seed用法及代碼示例
- Python numpy random.mtrand.RandomState.triangular用法及代碼示例
注:本文由純淨天空篩選整理自numpy.org大神的英文原創作品 numpy.right_shift。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。