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

Python에서 배열 요소의 삼각법 역코사인 가져오기

<시간/>

arccos는 다중값 함수입니다. 각 x에 대해 cos(z)=x와 같은 무한히 많은 숫자 z가 있습니다. 규칙은 실수부가 [0, pi]에 있는 각도 z를 반환하는 것입니다. 역 cos는 cos 또는 cos^-1이라고도 합니다.

실수 값 입력 데이터 유형의 경우 arccos는 항상 실수 출력을 반환합니다. 실수 또는 무한대로 표현할 수 없는 각 값에 대해 nan을 생성하고 잘못된 부동 소수점 오류 플래그를 설정합니다. 복소수 값 입력의 경우 arccos는 분기 절단 [-inf, -1] 및 [1, inf]이 있고 전자는 위에서부터 후자는 아래에서 연속인 복소 분석 함수입니다.

배열 요소의 삼각법 역코사인을 찾으려면 Python Numpy에서 numpy.arccos() 메서드를 사용합니다. 이 메서드는 지정된 x좌표 라디안 [0, pi]에서 단위 원과 교차하는 배열의 각도를 반환합니다. x가 스칼라이면 이것은 스칼라입니다.

첫 번째 매개변수 x는 단위 원의 x 좌표입니다. 실제 인수의 경우 도메인은 [-1, 1]이며 두 번째 및 세 번째 매개 변수는 선택 사항입니다. 두 번째 매개변수는 결과가 저장되는 위치인 ndarray입니다. 제공된 경우 입력이 브로드캐스트하는 모양이 있어야 합니다. orNone을 제공하지 않으면 새로 할당된 배열이 반환됩니다.

세 번째 매개변수는 조건이 입력을 통해 브로드캐스트된다는 것입니다. 조건이 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.arccos(arr))

예시

import numpy as np

# To find the Trigonometric inverse cosine of the array elements, use the numpy.arccos() method in Python Numpy
# The method returns the angle of the array intersecting the unit circle at the given x-coordinate in radians [0, pi]. This is a scalar if x is a scalar.
# The 1st parameter, x is the x-coordinate on the unit circle. For real arguments, the domain is [-1, 1].

print("Get the Trigonometric inverse cosine 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 cosine of the array elements
print("\nResult...",np.arccos(arr))

출력

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

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

Our Array type...
float64

Our Array Dimensions...
1

Number of elements...
4

Result... [0. 3.14159265 1.57079633 1.26610367]