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

Python에서 복잡한 점 배열로 주어진 차수의 Vandermonde 행렬 생성

<시간/>

주어진 차수의 Vandermonde 행렬을 생성하려면 Python Numpy에서 polynomial.polyvander()를 사용하십시오. 이 메서드는 Vandermonde 행렬을 반환합니다. 반환된 행렬의 모양은 x.shape + (deg + 1,)이며, 여기서 마지막 인덱스는 x의 거듭제곱입니다. dtype은 변환된 x와 동일합니다.

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

단계

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

numpy를 numpy.polynomial.polynomial 가져오기 폴리밴더에서 np로 가져오기

배열 생성 -

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

배열 표시 -

print("우리 배열...\n",x)

치수 확인 -

print("\n배열의 차원...\n",x.ndim)

데이터 유형 가져오기 -

print("\n배열 개체의 데이터 유형...\n",x.dtype)

모양 가져오기 -

print("\n배열 개체의 모양...\n",x.shape)

주어진 차수의 Vandermonde 행렬을 생성하려면 Python Numpy에서 polynomial.polyvander()를 사용하십시오 -

print("\n결과...\n",polyvander(x, 2))

numpy를 numpy.polynomial.polynomial import polyvander에서 np로 가져오기# 배열 생성x =np.array([-2.+2.j, -1.+2.j, 0.+2.j, 1.+ 2.j, 2.+2.j])# Display the arrayprint("Our Array...\n",x)# Check the Dimensionsprint("\nDimensions of our Array...\n",x.ndim )# Get Datatypeprint("\nDatatype of our Array object...\n",x.dtype)# Get Shapeprint("\nShape of our Array object...\n",x.shape)# 생성하려면 주어진 차수의 Vandermonde 행렬, Python에서 polynomial.polyvander() 사용 Numpyprint("\nResult...\n",polyvander(x, 2))

출력

우리의 배열...[-2.+2.j -1.+2.j 0.+2.j 1.+2.j 2.+2.j]우리 배열의 차원...1데이터 유형 배열 객체의...complex128배열 객체의 모양...(5,)결과...[[ 1.+0.j -2.+2.j 0.-8.j][ 1.+0 .j -1.+2.j -3.-4.j][ 1.+0.j 0.+2.j -4.+0.j][ 1.+0.j 1.+2. j -3.+4.j][ 1.+0.j 2.+2.j 0.+8.j]]