Python NumPy에서 라게르(Laguerre) 다항식의 의사 Vandermonde 행렬을 x, y, z 샘플 점과 함께 생성하려면 numpy.polynomial.laguerre 모듈의 lagvander3d() 함수를 사용합니다. 이 함수는 3개의 독립 변수에 대한 라게르 다항식 기저 함수 값을 계산하여 3차원 의사 Vandermonde 행렬을 반환합니다.
주요 매개변수는 다음과 같습니다.
- x, y, z: 점 좌표 배열입니다. dtype은 요소 중 하나라도 복소수이면 complex128로, 그렇지 않으면 float64로 자동 변환됩니다. 입력이 스칼라인 경우 1차원 배열로 변환됩니다.
- deg:
[x_deg, y_deg, z_deg]형태의 최대 차수 리스트입니다.
단계별 구현 방법
먼저 필요한 라이브러리를 임포트합니다.
import numpy as np from numpy.polynomial import laguerre as L
numpy.array() 메서드를 사용하여 동일한 형태(shape)를 가진 점 좌표 배열을 생성합니다.
x = np.array([-2.+2.j, -1.+2.j]) y = np.array([0.+2.j, 1.+2.j]) z = np.array([2.+2.j, 3.+3.j])
생성된 배열들을 출력합니다.
print("Array1...\n",x)
print("\nArray2...\n",y)
print("\nArray3...\n",z)배열들의 데이터 타입(dtype)을 확인합니다.
print("\nArray1 datatype...\n",x.dtype)
print("\nArray2 datatype...\n",y.dtype)
print("\nArray3 datatype...\n",z.dtype)배열들의 차원(ndim)을 확인합니다.
print("\nDimensions of Array1...\n",x.ndim)
print("\nDimensions of Array2...\n",y.ndim)
print("\nDimensions of Array3...\n",z.ndim)배열들의 형태(shape)를 확인합니다.
print("\nShape of Array1...\n",x.shape)
print("\nShape of Array2...\n",y.shape)
print("\nShape of Array3...\n",z.shape)이제 lagvander3d() 함수를 호출하여 x, y, z 샘플 점에 대한 라게르 다항식의 의사 Vandermonde 행렬을 생성합니다.
x_deg, y_deg, z_deg = 2, 3, 4
print("\nResult...\n",L.lagvander3d(x,y,z, [x_deg, y_deg, z_deg]))전체 예제 코드
import numpy as np
from numpy.polynomial import laguerre as L
# numpy.array() 메서드로 동일한 형태의 점 좌표 배열 생성
x = np.array([-2.+2.j, -1.+2.j])
y = np.array([0.+2.j, 1.+2.j])
z = np.array([2.+2.j, 3.+3.j])
# 배열 출력
print("Array1...\n",x)
print("\nArray2...\n",y)
print("\nArray3...\n",z)
# 데이터 타입 출력
print("\nArray1 datatype...\n",x.dtype)
print("\nArray2 datatype...\n",y.dtype)
print("\nArray3 datatype...\n",z.dtype)
# 배열의 차원 확인
print("\nDimensions of Array1...\n",x.ndim)
print("\nDimensions of Array2...\n",y.ndim)
print("\nDimensions of Array3...\n",z.ndim)
# 배열의 형태 확인
print("\nShape of Array1...\n",x.shape)
print("\nShape of Array2...\n",y.shape)
print("\nShape of Array3...\n",z.shape)
# lagvander3d()로 라게르 다항식의 의사 Vandermonde 행렬 생성
x_deg, y_deg, z_deg = 2, 3, 4
print("\nResult...\n",L.lagvander3d(x,y,z, [x_deg, y_deg, z_deg]))실행 결과
Array1...
[-2.+2.j -1.+2.j]
Array2...
[0.+2.j 1.+2.j]
Array3...
[2.+2.j 3.+3.j]
Array1 datatype...
complex128
Array2 datatype...
complex128
Array3 datatype...
complex128
Dimensions of Array1...
1
Dimensions of Array2...
1
Dimensions of Array3...
1
Shape of Array1...
(2,)
Shape of Array2...
(2,)
Shape of Array3...
(2,)
Result...
[[ 1. +0.j -1. -2.j
-3. +0.j -2.33333333 +3.33333333j
1. +5.33333333j 1. -2.j
-5. +0.j -3. +6.j
4.33333333 +8.j 11.66666667 +3.33333333j
-1. -4.j -7. +6.j
3. +12.j 15.66666667 +6.j
20.33333333 -9.33333333j -5. -4.66666667j
-4.33333333 +14.66666667j 15. +14.j
27.22222222 -5.77777778j 19.88888889 -31.33333333j
3. -2.j -7. -4.j
-9. +6.j -0.33333333 +14.66666667j
13.66666667 +14.j -1. -8.j
-15. +10.j 3. +24.j
29. +15.33333333j 41.66666667 -13.33333333j
-11. -10.j -9. +32.j
33. +30.j 59. -13.33333333j
42.33333333 -68.66666667j -24.33333333 -4.j
16.33333333 +52.66666667j 73. +12.j
70.11111111 -71.77777778j -3. -133.77777778j
5. -8.j -21. -2.j
-15. +24.j 15. +35.33333333j
47.66666667 +18.66666667j -11. -18.j
-25. +40.j 33. +54.j
85.66666667 +5.33333333j 85. -76.66666667j
-37. -12.j 13. +86.j
111. +36.j 126.33333333 -95.33333333j
27. -209.33333333j -62.33333333 +16.66666667j
95.66666667 +108.j 187. -50.j
89.88888889 -246.66666667j -151.22222222 -315.77777778j]
[ 1. +0.j -2. -3.j
-5. +3.j 1. +9.j
11.5 +6.j 0. -2.j
-6. +4.j 6. +10.j
18. -2.j 12. -23.j
-2.5 -2.j -1. +11.5j
18.5 +2.5j 15.5 -24.5j
-16.75 -38.j -4.66666667 +0.33333333j
10.33333333 +13.33333333j 22.33333333 -15.66666667j
-7.66666667 -41.66666667j -55.66666667 -24.16666667j
2. -2.j -10. -2.j
-4. +16.j 20. +16.j
35. -11.j -4. -4.j
-4. +20.j 32. +8.j
32. -40.j -22. -70.j
-9. +1.j 21. +25.j
42. -32.j -18. -80.j
-109.5 -42.5j -8.66666667 +10.j
47.33333333 +6.j 13.33333333 -76.j
-98.66666667 -68.j -159.66666667 +63.j
1.5 -6.j -21. +7.5j
10.5 +34.5j 55.5 +7.5j
53.25 -60.j -12. -3.j
15. +42.j 69. -21.j
15. -111.j -120. -106.5j
-15.75 +12.j 67.5 +23.25j
42.75 -107.25j -123.75 -129.75j
-253.125 +43.5j -5. +28.5j
95.5 -42.j -60.5 -157.5j
-261.5 -16.5j -228.5 +297.75j ]]