numpy.polydiv(p1,p2)方法計算兩個多項式的除法,並返回多項式除法的商和餘數。
參數:
p1:[array_like or poly1D]Coefficients of dividend polynomial.
p2:[array_like or poly1D]Coefficients of divisor polynomial.返回:
q:[ndarray]Coefficients of quotient.
r:[ndarray]Coefficients of remainder.
代碼:解釋polydiv()的Python代碼
# Python code explaining
# numpy.polydiv()
# importing libraries
import numpy as np
import pandas as pd
# Constructing polynomial
p1 = np.poly1d([1, 2])
p2 = np.poly1d([4, 9, 5, 4])
print ("P1:", p1)
print ("\n p2:\n", p2)
quotient, remainder = np.polydiv(p2, p1)
print("\n\nquotient :", quotient)
print("remainder:", remainder)
print ("\n")
# Defining ndarray
x = np.array([1, 2])
y = np.array([4, 9, 5, 4])
quotient, remainder = np.polydiv(y, x)
print("quotient :", quotient)
print("remainder:", remainder)
相關用法
注:本文由純淨天空篩選整理自Mohit Gupta_OMG 大神的英文原創作品 numpy.polydiv() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。