데이터 분석/NumPy

파이썬 데이터사이언스 핸드북 2 장 - NumPy 지수와 로그 함수

haloaround 2020. 5. 23. 22:20

지수함수 Exponential Function 

출처  https://mathinsight.org/exponential_function

 

The exponential function - Math Insight

Overview of the exponential function The exponential function is one of the most important functions in mathematics (though it would have to admit that the linear function ranks even higher in importance). To form an exponential function, we let the indepe

mathinsight.org

 

 

로그함수 Logarithm Function

출처: https://mathinsight.org/logarithm_basics

 

Basic idea and rules for logarithms - Math Insight

The basic idea A logarithm is the opposite of a power. In other words, if we take a logarithm of a number, we undo an exponentiation. Let's start with simple example. If we take the base $b=2$ and raise it to the power of $k=3$, we have the expression $2^3

mathinsight.org

 

관련해서는 아래 더보기 클릭 

더보기

A. exponential function 지수함수

1. exponential function

독립변수 x 가 지수로 나타나는 함수

y = 3^x    
3 : base of exponents
x : actual exponent, multiply 3 for x times

 

2. exponential decay function

지수가 음수값이면 exponential decay function 이라고 부른다. 

y = (1/3)^x = 3^(-x) 

 

3. Expressions

구글 검색 계산기와 그래프를 통해서 간단한 계산 및 그래프를 확인할 수 있다.

10 ^ 6  = 1000000 : 10 to the sixth power is equal to 1 with six zeroes.

10^6 를 바로 검색해보자.

 

It can be described as plot and graph.

3^x 그래프에서 x=2 를 마우스오버하면 , y=9 plot 을 계산해준다. 

 

 

 

 

B. Linear fashion and Exponential fashion

그래프는 Linear 선형으로 증가/감소하는 양상을 띄기도 하고, Exponential 기하급수적으로 증가/감소하기도 한다. 

데이터 모델에서 2개의 개념 (그래프 양상) 이 나온다. 

 

1. Exponential Model  (Multiply/Divide)

Fidel has a rare coin worth $550. Each year the coin's value increase by 10% (every year)

--- multiplying by 1.1 every 1 year

The number of wild hogs in Arkansas increases by a factor of 3 every 5 years. 

--- multiplying by 3 every 5 years

 

2. Linear Model (Plus/Minus)

Your uncle bought a car for 130,000 Mexican pesos. Each year the value of the car decreases by 10,000 pesos.

You work as a waiter at a restaurant. You earn $50 in tips every day you work.

--- minus 10,000 / plus $50 

 

 

C. Logarithm Function

1. Logarithm function

power 지수함수와 상반되는 개념이다. 특정 숫자에 대해 로그값을 받으면, 우리는 지수를 해체한다. 

inverse of taking the exponent of something

log₂8 = 3  / 2³=8
base 2 of 8 is equal to 3

 

2. Expressions

 

D. Euler's number e

irrational number 무리수이고, 

not defined by geometry like Pi or squre roots, mathematical constant that is related to growth and rate of change

파이나 루트 처럼 기하학 개념에서 정의된 것이 아니라,성장과 변화의 비율에 대한 상수이다. 

 

원리

A * (1+1/1)¹    --- 1년에 1배수 이자를 1년동안 1년 단위로 복리 (compound index)

A * (1+1/(365*24*60*60))³⁶⁵*²⁴*⁶⁰*⁶⁰  --- 1초에 1/(365*24*60*60) 배수 이자 를 1년동안 1초 단위로 복리 

= 2.71828177847... 

= 1 + 1/1! + 1/2! + 1/3! + 1/4! + etc. in infinitum (fractions never end! so it tis irrational number)

 

Grapgh

euler's number graph 

 

 

출처: https://www.youtube.com/watch?v=AuA2EAgAegE

Euler's Number, simple is the best

 

NumPy 함수 - exp, expm 

 

Natural Exponential/Logarithmic Function

 

numpy.exp(x)

, Natural Exponential Functions with base e. 

Calculate the exponential of all elements in the input array, output ndarray or scalar

 

numpy.expm1(x)

exp(x) - 1 with greater precision

exp(x) minus 1 의 약자인듯? 

 

numpy.exp2(x)

, Calculate 2**p for all p in the input array.

numpy exponentials

 

NumPy 함수 - log 

numpy.log(x), numpy.log2(x), numpy.log10(x)

Return Natural logarithm, element-wise.

Return the base 2 logarithm of the input array, element-wise.

Return the base 10 logarithm of the input array, element-wise.

numpy logarithms

 

그 외 고급 Ufunc 기능

output

임시 배열을 새엉하지 않고, 지정한 배열을 이용해 원하는 메모리 위치에 직접 연산결과를 쓸 수 있다. 메모리를 절약할 수 있다. 

 

reducce, accmulate

reduce 메서드는 결과가 하나만 남을 때 까지 해당 연산을 배열 요소에 반복해서 적용한다.

accumulate 메서드는 계산의 중간 결과를 모두 저장하고 싶을 때 사용한다.