Computer >> 컴퓨터 >  >> 프로그램 작성 >> Python

Python에서 계수의 1D 배열을 사용하여 점 (x, y)에서 2차원 다항식 평가

<시간/>

점 (x, y)에서 2차원 다항식을 평가하려면 Python Numpy에서 polynomial.polyval2d() 메서드를 사용합니다. 이 방법은 x와 y의 해당 값 쌍, 즉 매개변수 x, y로 구성된 점에서 2차원 다항식의 값을 반환합니다. 2차원 계열은 점(x, y)에서 평가되며 여기서 x와 y는 모양이 같아야 합니다. x 또는 y가 목록 또는 튜플이면 먼저 ndarray로 변환되고, 그렇지 않으면 변경되지 않은 채로 남아 있고 ndarray가 아니면 스칼라로 처리됩니다.

매개변수 c는 다차 i,j 항의 계수가 c[i,j]에 포함되도록 정렬된 계수의 배열입니다. c의 차원이 2보다 크면 나머지 인덱스는 여러 계수 집합을 열거합니다. c의 차원이 2개 미만인 경우 1차원이 암시적으로 모양에 추가되어 2차원이 됩니다. 결과의 모양은 c.shape[2:] + x.shape입니다. c의 차원이 2개 미만인 경우 1차원이 암시적으로 모양에 추가되어 2차원이 됩니다. 결과의 모양은 c.shape[2:] + x.shape입니다.

단계

먼저 필요한 라이브러리를 가져옵니다. -

import numpy as np
from numpy.polynomial.polynomial import polyval2d

계수의 1차원 배열 생성 -

c = np.array([3, 5])

배열 표시 -

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)

점 (x, y)에서 2차원 다항식을 평가하려면 Python Numpy에서 polynomial.polyval2d() 메서드를 사용합니다. 이 방법은 x 및 y의 해당 값 쌍으로 구성된 점에서 2차원 다항식의 값을 반환합니다. -

print("\nResult...\n",polyval2d([1,2],[1,2], c))

예시

import numpy as np
from numpy.polynomial.polynomial import polyval2d

# Create a 1d array of coefficients
c = np.array([3, 5])

# 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 evaluate a 2-D polynomial at points (x, y), use the polynomial.polyval2d() method in Python Numpy

# The method returns the values of the two dimensional polynomial at points formed with pairs of corresponding values from x and y.
print("\nResult...\n",polyval2d([1,2],[1,2], c))

출력

Our Array...
[3 5]

Dimensions of our Array...
1

Datatype of our Array object...
int64

Shape of our Array object...
(2,)

Result...
[21. 34.]