2017년 5월 15일 월요일

2017년 3월 27일 월요일

[python] pandas subplot

fig, axes = plt.subplots(nrows=2, ncols=2)
fig.set_figheight(6)
fig.set_figwidth(8)
df[0].plot(ax=axes[0,0], style='r', label='Series'); axes[0,0].set_title(0)
df[1].plot(ax=axes[0,1]); axes[0,1].set_title(1)
df[2].plot(ax=axes[1,0]); axes[1,0].set_title(2)
df[3].plot(ax=axes[1,1]); axes[1,1].set_title(3)
fig.tight_layout()

2017년 3월 26일 일요일

[python] List Combine

import itertools

a = [ 1 , 1 ]
b = [ 2, 2 , 2]
c = [ 3 , 3 ]

result_A = a + b + c
result_B = list(itertools.chain(a,b,c))
a.extend(b)
a.extend(c)
result_C = a


print result_A
print result_B
print result_C

2017년 3월 20일 월요일

[python] flatten vs ravel

import numpy as np
y = np.array(((1,2,3),(4,5,6),(7,8,9)))
OUTPUT:
print(y.flatten())
[1   2   3   4   5   6   7   8   9]
print(y.ravel())
[1   2   3   4   5   6   7   8   9]


As explained here a key difference is that flatten is a method of an ndarray object and hence can only be called for true numpy arrays. In contrast ravel() is a library-level function and hence can be called on any object that can successfully be parsed. For example ravel() will work on a list of ndarrays, while flatten is not available for that type of object.

[algorithmn] 리스트의 순서를 바꾸지 않고, 각 값에 그 값의 크기에 할당된 크기의 값리스트 생성

[ 10 ,1 ,5 ] 시 [255 , 0 , 130 ] 의 리스트를 만드는것.

[1 , 10 ,5 ] 시 [0 , 255, 130] 이 된다.



1. [10, 1 ,  5] 의 크기순 set 을 만듬 => target_compare = [ 3, 1 , 2]

2. subset = [ 0 , 130 , 255] 만듬

3. result  = [ subset[i] for i in  target_compare  ]

2017년 3월 16일 목요일

[statistic] summery

- correlation
http://ezstat.snu.ac.kr/textbook_sources/chapter_05.pdf
https://en.wikipedia.org/wiki/Correlation_and_dependence

-

2017년 3월 15일 수요일

[python] Decorator

http://trowind.tistory.com/72
함수버전

def verbose(func):
print "Begin", func.__name__;
func();
print "End", func.__name__;

@verbose
def my_function():
print "hello, world."

my_functiont() 시

실제로는

verbose(my_function)

이 실행된다.


-----------------------
클래스버전

class Verbose:
def __init__(self, f):
print "Initializing Verbose."
self.tt = f;

def __call__(self):
print "Begin", self.tt.__name__
self.tt();
print "End", self.tt.__name__

@Verbose
def my_function():
    print "hello, world."


print "Program start"
my_function();


먼저 클래스의 __init__은 f라는 함수를 받는다.

그리고 __call__이란 부분이 데코레이터시 실행되는 부분이다 .

이건 실제로는

my_funtion() 을 실행시 Verbose.__call__(my_function) 이 실행된다.

즉 실제로는 아래와 같이 실행된다.

class Verbose:
def __init__(self, f):
print "Initializing Verbose."
self.tt = f;

def __call__(self):
print "Begin", self.tt.__name__
self.tt();
print "End", self.tt.__name__


def my_function():
    print "hello, world."

print "Program start"
ver = Verbose(my_function)
ver.__call__()