當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python numpy.polymul()用法及代碼示例

numpy.polymul(p1,p2)方法計算兩個多項式的乘積,並返回兩個輸入多項式“ p1”和“ p2”相乘所得的多項式。

參數:
p1:[array_like or poly1D]Input polynomial 1.
p2:[array_like or poly1D]Input polynomial 2.

返回: Polynomial resulting from multiplication of the inputs.



如果任一輸入為poly1D 對象,則輸出也是一個poly1D對象,否則,按降序排列的多項式係數的1D數組。

代碼:解釋polymul()的Python代碼

# Python code explaining  
# numpy.polymul() 
    
# 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) 

mul = np.polymul(p2, p1) 
  
print("\n\npoly1D object:") 
print("Multiplication Result :\n", mul)

# Defining ndarray 
x = np.array([1, 2]) 
y = np.array([4, 9, 5, 4]) 
mul = np.polymul(y, x) 
  
print("\n1D array:") 
print("Multiplication Result :", mul)



相關用法


注:本文由純淨天空篩選整理自Mohit Gupta_OMG 大神的英文原創作品 numpy.polymul() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。