Python NumPy에서 polynomial.laguerre.lagval2d() 메서드를 사용하면 지정한 점 (x, y)에서 2차원 라게르(Laguerre) 급수를 간편하게 평가할 수 있습니다. 이 메서드는 x와 y에서 대응하는 값들의 쌍으로 구성된 각 점에 대해 2차원 다항식의 값을 계산하여 반환합니다.
lagval2d() 메서드의 매개변수 이해하기
첫 번째 매개변수 (x, y): 2차원 급수를 평가할 점 (x, y)를 의미합니다. 이때 x와 y는 반드시 동일한 형태(shape)를 가져야 합니다. x 또는 y가 리스트(list)나 튜플(tuple)로 전달되면 먼저 ndarray로 변환되며, 이미 ndarray인 경우에는 그대로 사용됩니다. 만약 ndarray가 아니라면 스칼라(scalar) 값으로 취급됩니다.
두 번째 매개변수 (C): 계수(coefficient) 배열입니다. 다중 차수(multidegree) i, j에 해당하는 항의 계수가 c[i, j]에 저장되도록 정렬되어 있습니다. 만약 c의 차원이 2보다 크다면, 나머지 인덱스들은 여러 개의 계수 집합을 나타내는 데 사용됩니다.
단계별 구현 방법
1단계: 필요한 라이브러리 임포트
먼저 필요한 라이브러리를 가져옵니다.
import numpy as np
from numpy.polynomial import laguerre as L
2단계: 계수용 다차원 배열 생성
계수를 담을 다차원 배열을 생성합니다.
c = np.array([[1,2],[3,4]])
3단계: 배열 출력하기
print("Our Array...\n",c)
4단계: 배열의 차원 확인하기
print("\nDimensions of our Array...\n",c.ndim)
5단계: 데이터 타입 확인하기
print("\nDatatype of our Array object...\n",c.dtype)
6단계: 배열의 형태(shape) 확인하기
print("\nShape of our Array object...\n",c.shape)
7단계: 2D 라게르 급수 평가하기
점 (x, y)에서 2차원 라게르 급수를 평가하려면 polynomial.laguerre.lagval2d() 메서드를 사용합니다.
print("\nResult...\n",L.lagval2d([1,2],[1,2],c))
전체 예제 코드
import numpy as np
from numpy.polynomial import laguerre as L
# 계수용 다차원 배열 생성
c = np.array([[1,2],[3,4]])
# 배열 출력
print("Our Array...\n",c)
# 차원 확인
print("\nDimensions of our Array...\n",c.ndim)
# 데이터 타입 확인
print("\nDatatype of our Array object...\n",c.dtype)
# 형태(shape) 확인
print("\nShape of our Array object...\n",c.shape)
# lagval2d() 메서드로 점 (x, y)에서 2D 라게르 급수 평가
print("\nResult...\n",L.lagval2d([1,2],[1,2],c))
실행 결과
Our Array...
[[1 2]
[3 4]]
Dimensions of our Array...
2
Datatype of our Array object...
int64
Shape of our Array object...
(2, 2)
Result...
[1. 0.]