다항식 계수의 1차원 배열의 컴패니언 행렬을 반환하려면 Python Numpy에서 polynomial.polycompanion() 메서드를 반환합니다. 거듭제곱 급수의 컴패니언 행렬은 기저를 스케일링하여 대칭이 될 수 없으므로 이 함수는 직교 다항식의 함수와 다릅니다. 이 메서드는 차원(deg, deg)의 컴패니언 행렬을 반환합니다. 매개변수 c는 낮은 차수에서 높은 차수로 정렬된 다항식 계수의 1차원 배열입니다.
단계
먼저 필요한 라이브러리를 가져옵니다 -
import numpy as np from numpy.polynomial.polynomial import polycompanion
계수의 1D 배열 생성 -
c = np.array([1, 2, 3])
배열 표시 -
print("Our Array...\n",c) 치수 확인 -
print("\nDimensions of our Array...\n",c.ndim)
데이터 유형 가져오기 -
print("\nDatatype of our Array object...\n",c.dtype) 모양 가져오기 -
print("\nShape of our Array object...\n",c.shape)
다항식 계수의 1차원 배열의 컴패니언 행렬을 반환하려면 polynomial.polycompanion() 메서드를 반환합니다. -
print("\nResult...\n",polycompanion(c)) 예시
import numpy as np
from numpy.polynomial.polynomial import polycompanion
# Create a 1D array of coefficients
c = np.array([1, 2, 3])
# Display the array
print("Our Array...\n",c)
# Check the Dimensions
print("\nDimensions of our Array...\n",c.ndim)
# Get the Datatype
print("\nDatatype of our Array object...\n",c.dtype)
# Get the Shape
print("\nShape of our Array object...\n",c.shape)
# To return the companion matrix of a 1-D array of polynomial coefficients, return the polynomial.polycompanion() method in Python Numpy
print("\nResult...\n",polycompanion(c)) 출력
Our Array... [1 2 3] Dimensions of our Array... 1 Datatype of our Array object... int64 Shape of our Array object... (3,) Result... [[ 0. -0.33333333] [ 1. -0.66666667]]