借助Numpy ndarray.__imod__()
,數組中的每個元素都使用二進製運算符(即mod(%))進行操作。請記住,我們可以在數組中使用任何類型的值,而mod的值將作為ndarray.__imod__()
。
用法: ndarray.__imod__($self, value, /)
返回:self%=value
範例1:
在此示例中,我們可以看到傳遞的值ndarray.__imod__()
方法用於對數組的每個元素執行mod操作。
# import the important module in python
import numpy as np
# make an array with numpy
gfg = np.array([1, 2.5, 3, 4.8, 5])
# applying ndarray.__imod__() method
print(gfg.__imod__(2))
輸出:
[ 1. 0.5 1. 0.8 1. ]
範例2:
# import the important module in python
import numpy as np
# make an array with numpy
gfg = np.array([[1, 2, 3, 4.45, 5],
[6, 5.5, 4, 3, 2.62]])
# applying ndarray.__imod__() method
print(gfg.__imod__(3))
輸出:
[[ 1. 2. 0. 1.45 2. ] [ 0. 2.5 1. 0. 2.62]]
相關用法
- Python Numpy numpy.ndarray.__mod__()用法及代碼示例
- Python Numpy numpy.ndarray.__ge__()用法及代碼示例
- Python Numpy numpy.ndarray.__invert__()用法及代碼示例
- Python Numpy numpy.ndarray.__divmod__()用法及代碼示例
- Python Numpy numpy.ndarray.__eq__()用法及代碼示例
- Python Numpy numpy.ndarray.__pow__()用法及代碼示例
- Python Numpy numpy.ndarray.__rshift__()用法及代碼示例
- Python Numpy numpy.ndarray.__le__()用法及代碼示例
- Python Numpy numpy.ndarray.__lt__()用法及代碼示例
- Python Numpy numpy.ndarray.__gt__()用法及代碼示例
- Python Numpy numpy.ndarray.__truediv__()用法及代碼示例
- Python Numpy numpy.ndarray.__mul__()用法及代碼示例
- Python Numpy numpy.ndarray.__sub__()用法及代碼示例
- Python Numpy numpy.ndarray.__pos__()用法及代碼示例
- Python Numpy numpy.ndarray.__add__()用法及代碼示例
注:本文由純淨天空篩選整理自Jitender_1998大神的英文原創作品 Python | Numpy ndarray.__imod__()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。