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

Python에서 Legendre 시리즈의 Vandermonde 행렬 생성

<시간/>

르장드르 다항식의 의사 Vandermonde 행렬을 생성하려면 Python Numpy에서 polynomial.legvander() 메서드를 사용하십시오.

이 메서드는 의사 Vandermonde 행렬을 반환합니다. 반환된 행렬의 모양은 x.shape +(deg + 1,)입니다. 여기서 마지막 인덱스는 해당 르장드르 다항식의 차수입니다. dtype은 변환된 x와 동일합니다.

매개변수 x는 포인트 배열을 반환합니다. 복잡한 요소가 있는지 여부에 따라 dtype이 float64 또는 complex128로 변환됩니다. x가 스칼라이면 1차원 배열로 변환됩니다. 매개변수 deg는 결과 행렬의 차수입니다.

단계

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

import numpy as np
from numpy.polynomial import legendre as L

배열 생성 -

x = np.array([0, 1, -1, 2])

배열 표시 -

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)

르장드르 다항식의 의사 Vandermonde 행렬을 생성하려면 Python에서 polynomial.legvander() 메서드를 사용하십시오 -

print("\nResult...\n",L.legvander(x, 2))

예시

import numpy as np
from numpy.polynomial import legendre as L

# Create an array
x = np.array([0, 1, -1, 2])

# Display the array
print("Our Array...\n",x)

# Check the Dimensions
print("\nDimensions of our Array...\n",x.ndim)

# Get the Datatype
print("\nDatatype of our Array object...\n",x.dtype)

# Get the Shape
print("\nShape of our Array object...\n",x.shape)

# To generate a pseudo Vandermonde matrix of the Legendre polynomial, use the polynomial.legvander() method in Python Numpy
print("\nResult...\n",L.legvander(x, 2))

출력

Our Array...
   [ 0 1 -1 2]

Dimensions of our Array...
1

Datatype of our Array object...
int64

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

Result...
   [[ 1. 0. -0.5]
   [ 1. 1. 1. ]
   [ 1. -1. 1. ]
   [ 1. 2. 5.5]]