Python numpy.reeminder()

Python numpy.reeminder()

numpy.remainder()是另一个在numpy中进行数学运算的函数,它返回两个数组arr1和arr2之间除法的逐元余数,即arr1 % arr2.当arr2为0并且arr1和arr2都是(整数的)数组时,它返回0。

语法: numpy.remainder(arr1, arr2, /, out=None, *, where=True, casting=’same_kind’, order=’K’, dtype=None, subok=True[, signature, extobj], ufunc ‘remainder’)

参数 :
arr1 : [array_like] 红利阵列。
arr2 : [array_like] 除数数组。
dtype : 返回数组的类型。默认情况下,使用Arr的dtype。
out : [ndarray, optional] 一个储存结果的位置。
-> 如果提供,它必须有一个输入广播到的形状。
-> 如果没有提供或没有,将返回一个新分配的数组。
where : [array_like, optional] 数值为True表示在该位置计算ufunc,数值为False表示在输出中不考虑该值。
**kwargs :允许向一个函数传递关键字的可变长度的参数。当我们想在一个函数中处理命名的参数时使用。

返回: [ndarray] 元素间的余数,即 arr1 % arr2 。

代码#1:

# Python program explaining
# numpy.remainder() function
  
import numpy as geek
in_num1 = 4
in_num2 = 6
  
print ("Dividend : ", in_num1)
print ("Divisor : ", in_num2)
    
out_num = geek.remainder(in_num1, in_num2) 
print ("Remainder : ", out_num) 

输出 :

Dividend :  4
Divisor :  6
Remainder :  4

代码#2:

# Python program explaining
# numpy.remainder() function
  
import numpy as geek
  
in_arr1 = geek.array([5, -4, 8])
in_arr2 = geek.array([2, 3, 4])
   
print ("Dividend array : ", in_arr1)
print ("Divisor array : ", in_arr2)
   
    
out_arr = geek.remainder(in_arr1, in_arr2) 
print ("Output remainder array: ", out_arr) 

输出 :

Dividend array :  [ 5 -4  8]
Divisor array :  [2 3 4]
Output remainder array:  [1 2 0]

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

Numpy 数学函数