logo

Python의 로그 함수

Python은 모듈 아래에 많은 내장 로그 함수를 제공합니다. 수학 이를 통해 단일 라인을 사용하여 로그를 계산할 수 있습니다. 로그 함수에는 4가지 변형이 있으며, 모두 이 문서에서 설명합니다.
1. log(a,(Base)) : 이 함수는 다음을 계산하는 데 사용됩니다. 자연로그 (기본 e)의 a. 2개의 인수가 전달되면 인수 a의 원하는 밑수에 대한 로그, 즉 숫자 값을 계산합니다. 로그(a)/로그(기본) .

 Syntax : math.log(a,Base) Parameters :  a : The numeric value Base : Base to which the logarithm has to be computed. Return Value :  Returns natural log if 1 argument is passed and log with specified base if 2 arguments are passed. Exceptions :  Raises ValueError if a negative no. is passed as argument.>

파이썬3



역방향 문자열 자바






# Python code to demonstrate the working of> # log1p(a)> import> math> # Printing the log(1+a) of 14> print> (>'Logarithm(1+a) value of 14 is : '>, end>=>'')> print> (math.log1p(>14>))>



>

>

출력 :

Natural logarithm of 14 is : 2.6390573296152584 Logarithm base 5 of 14 is : 1.6397385131955606>

2. 로그2(a) : 이 함수는 다음을 계산하는 데 사용됩니다. 대수 밑 2 의 log(a,2)보다 더 정확한 결과를 표시합니다.

 Syntax : math.log2(a) Parameters :  a : The numeric value Return Value :  Returns logarithm base 2 of a Exceptions :  Raises ValueError if a negative no. is passed as argument.>

파이썬3




# Python code to demonstrate the Exception of> # log(a)> import> math> # Printing the log(a) of -14> # Throws Exception> print> (>'log(a) value of -14 is : '>, end>=>'')> print> (math.log(>->14>))>

>

>

출력 :

Logarithm base 2 of 14 is : 3.807354922057604>

3. 로그10(a) : 이 함수는 다음을 계산하는 데 사용됩니다. 로그 밑수 10 의 log(a,10)보다 더 정확한 결과를 표시합니다.

 Syntax : math.log10(a) Parameters :  a : The numeric value Return Value :  Returns logarithm base 10 of a Exceptions :  Raises ValueError if a negative no. is passed as argument.>

파이썬3




# Python code to demonstrate the Application of> # log10(a)> import> math> # Printing no. of digits in 73293> print> (>'The number of digits in 73293 are : '>, end>=>'')> print> (>int>(math.log10(>73293>)>+> 1>))>

>

>

출력 :

Logarithm base 10 of 14 is : 1.146128035678238>

3. log1p(a) : 이 함수는 계산하는 데 사용됩니다. 로그(1+a) .

 Syntax : math.log1p(a) Parameters :  a : The numeric value Return Value :  Returns log(1+a) Exceptions :  Raises ValueError if a negative no. is passed as argument.>

파이썬3




>

>

출력 :

Logarithm(1+a) value of 14 is : 2.70805020110221>
예외

1. 값 오류: 이 함수는 숫자가 다음과 같은 경우 값 오류를 반환합니다. 부정적인 .

파이썬3




# Python code to demonstrate the Exception of> # log(a)> import> math> # Printing the log(a) of -14> # Throws Exception> print> (>'log(a) value of -14 is : '>, end>=>'')> print> (math.log(>->14>))>

>

>

출력 :

log(a) value of -14 is :>

런타임 에러 :

Traceback (most recent call last): File '/home/8a74e9d7e5adfdb902ab15712cbaafe2.py', line 9, in print (math.log(-14)) ValueError: math domain error>
실용적인 응용 프로그램

log10() 함수의 응용 중 하나는 다음을 계산하는 데 사용된다는 것입니다. 아니요. 숫자의 자릿수 . 아래 코드는 동일한 내용을 보여줍니다.

파이썬3




# Python code to demonstrate the Application of> # log10(a)> import> math> # Printing no. of digits in 73293> print> (>'The number of digits in 73293 are : '>, end>=>'')> print> (>int>(math.log10(>73293>)>+> 1>))>

>

>

출력 :

The number of digits in 73293 are : 5>

자연 로그(log)는 과학 컴퓨팅, 데이터 분석 및 기계 학습 응용 프로그램에서 자주 사용되는 Python의 중요한 수학 함수입니다. 다음은 Python의 로그 함수와 관련된 몇 가지 장점, 단점, 중요 사항 및 참고 도서입니다.

장점:

로그 함수는 값의 범위가 넓거나 비정규 분포를 갖는 데이터를 보다 정규 분포 형태로 변환하는 데 유용하며, 이를 통해 통계 분석 및 기계 학습 모델의 정확도를 높일 수 있습니다.
로그 함수는 금융 및 경제 분야에서 복리, 현재 가치 및 기타 재무 지표를 계산하는 데 널리 사용됩니다.
로그 함수를 사용하면 데이터 규모를 압축하여 통계 분석에 대한 이상값의 영향을 줄일 수 있습니다.
로그 함수를 사용하면 동적 범위가 크거나 0에 가까운 값으로 데이터를 시각화할 수 있습니다.

단점:

로그 함수는 대규모 데이터 세트의 경우 계산 비용이 많이 들 수 있으며, 특히 로그 함수가 반복적으로 적용되는 경우 더욱 그렇습니다.
로그 함수는 범주형 데이터나 제한된 범위의 데이터 등 모든 유형의 데이터에 적합하지 않을 수 있습니다.

중요 사항:

  1. 자연 로그(log)는 Python의 numpy.log() 함수를 사용하여 계산됩니다.
  2. e가 아닌 밑을 갖는 로그는 Python에서 numpy.log10() 또는 numpy.log2() 함수를 사용하여 계산할 수 있습니다.
  3. 자연 로그의 역함수는 Python에서 numpy.exp() 함수를 사용하여 계산할 수 있는 지수 함수입니다.
  4. 통계 분석이나 기계 학습을 위해 로그를 사용할 때는 분석 후 데이터를 원래 규모로 다시 변환하는 것을 기억하는 것이 중요합니다.

참고 도서:

Wes McKinney의 데이터 분석을 위한 Python은 NumPy 라이브러리와 로그 함수를 포함하여 데이터 분석에 대한 심층적인 애플리케이션을 다루고 있습니다.
Numerical Python: A Practical Techniques Approach for Robert Johansson은 NumPy 라이브러리와 로그 함수를 포함한 수치 컴퓨팅 및 과학 컴퓨팅 분야의 애플리케이션을 심층적으로 다루고 있습니다.
Jake VanderPlas가 쓴 Python 데이터 과학 핸드북은 로그 함수를 포함하여 NumPy 라이브러리와 데이터 과학의 애플리케이션을 심층적으로 다루고 있습니다.