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

Python에서 배열 요소의 삼각 역탄젠트 가져오기

<시간/>

arctan은 다중값 함수입니다. 각 x에 대해 tan(z)=x와 같은 무한히 많은 숫자 z가 있습니다. # 역탄젠트는 atan 또는 tan^{-1}이라고도 합니다.

관례는 실수부가 [-pi/2, pi/2]에 있는 각도 z를 반환하는 것입니다. 실수 값 입력 데이터 유형의 경우 arctan은 항상 실제 출력을 반환합니다. 실수 또는 무한대로 표현할 수 없는 각 값에 대해 nan을 생성하고 잘못된 부동 소수점 오류 플래그를 설정합니다. 복소수 값 입력의 경우 arctan은 분기 절단으로 [1j, infj] 및 [-1j, -infj]를 갖는 복소 분석 함수이며 전자는 왼쪽에서, 후자는 오른쪽에서 연속입니다.

배열 요소의 삼각법 역탄젠트를 찾으려면 Python Numpy에서 numpy.arctan() 메서드를 사용합니다. 이 메서드는 tan의 역함수를 반환하므로 y =tan(x)이면 x =arctan(y)입니다. 첫 번째 매개변수는 배열과 유사합니다. 두 번째 및 세 번째 매개변수는 선택 사항입니다. 두 번째 매개변수는 결과가 저장되는 ndarray입니다. 제공된 경우 입력이 브로드캐스트하는 모양이 있어야 합니다. 제공되지 않거나 None이면 새로 할당된 배열이 반환됩니다. Atuple의 길이는 출력 수와 동일해야 합니다.

세 번째 매개변수는 조건이 입력을 통해 브로드캐스트된다는 것입니다. 조건이 True인 위치에서 out 배열은 ufunc 결과로 설정됩니다. 다른 곳에서는 out 배열이 원래 값을 유지합니다.

단계

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

import numpy as np

배열 요소의 삼각 역탄젠트를 가져옵니다. numpy.array() 메서드를 사용하여 생성된 배열 -

arr = np.array((1, -1, 0, 0.3))

배열 표시하기 -

print("Array...\n",arr)

데이터 유형 가져오기 -

print("\nArray datatype...\n",arr.dtype)

배열의 차원 가져오기 -

print("\nArray Dimensions...\n",arr.ndim)

배열의 요소 수 가져오기 -

print("\nNumber of elements in the Array...\n",arr.size)

배열 요소의 삼각 역탄젠트 찾기 -

print("\nResult...",np.arctan(arr))

예시

import numpy as np

# To find the Trigonometric inverse tangent of the array elements, use the numpy.arctan() method in Python Numpy
# The method returns the The inverse of tan, so that if y = tan(x) then x = arctan(y).

print("Get the Trigonometric inverse tangent of the array elements...\n")

# Array created using the numpy.array() method
arr = np.array((1, -1, 0, 0.3))

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

# Get the type of the array
print("\nOur Array type...\n", arr.dtype)

# Get the dimensions of the Array
print("\nOur Array Dimensions...\n",arr.ndim)

# Get the number of elements in the Array
print("\nNumber of elements...\n", arr.size)

# Finding the Trigonometric inverse tangent of the array elements
print("\nResult...",np.arctan(arr))

출력

Get the Trigonometric inverse tangent of the array elements...

Array...
[ 1. -1. 0. 0.3]

Our Array type...
float64

Our Array Dimensions...
1

Number of elements...
4

Result... [ 0.78539816 -0.78539816 0. 0.29145679]