The divmod() function returns both the quotient and the remainder. The output consists of two arrays: the first array contains the quotients, while the second array contains the remainders.
Return the quotient and remainder:
import numpy as np arr1 = np.array([10, 20, 30, 40, 50, 60]) arr2 = np.array([3, 7, 9, 8, 2, 33]) newarr = np.divmod(arr1, arr2) print(newarr) |
The example above will return:(array([3, 2, 3, 5, 25, 1]), array([1, 6, 3, 0, 0, 27])) The first array represents the quotients (the integer results of dividing 1010 by 33, 2020 by 77, 3030 by 99, and so on), while the second array represents the remainders from the same divisions. |
Both the absolute() and abs() functions perform the absolute operation element-wise, but it is advisable to use absolute() to avoid confusion with Python’s built-in math.abs().
Return the quotient and remainder:
import numpy as np arr = np.array([-1, –2, 1, 2, 3, –4]) newarr = np.absolute(arr) print(newarr) |