N = int(input())

def fibonach(f_1, f_2, cnt):
    f_n = f_1 + f_2

    if(cnt == 0):
        return f_n
    else:
        return fibonach(f_2, f_n, cnt - 1)
    
if(N == 0):
    print(0)
elif(N == 1):
    print(1)
else:
    print(fibonach(0, 1, N - 2))


import sys

N, K = map(int, input().split())
prefered = list(map(int, input().split()))

min_std = float('inf')

while(K != (N + 1)):
    stride = 1
    full_range = ((N - K) // stride) + 1
    
    for i in range(full_range):
        do_list = prefered[i:(i + K)]
        mean = sum(do_list) / K
        var = sum([(x - mean) ** 2 for x in do_list]) / K
        std = var ** 0.5
        if(min_std >= std):
            min_std = std
    K += 1
sys.stdout.write(str(min_std))

'# 코딩 문제 관련 > 파이썬' 카테고리의 다른 글

백준 1003번(python)  (0) 2019.07.31
백준 2748번(python)  (0) 2019.07.31
백준 카카오 코드 페스티벌 예선 15953번(python)  (0) 2019.07.30
백준 10814번(python)  (3) 2019.07.19
백준 11650번(python)  (0) 2019.07.19


Case = int(input())

def check_money(code_1, code_2):
    if((code_1 > 0) and (code_1 < 101)):
        if(code_1 <= 1):
            money_1 = 5000000
        elif(code_1 <= 3):
            money_1 = 3000000
        elif(code_1 <= 6):
            money_1 = 2000000
        elif(code_1 <= 10):
            money_1 = 500000
        elif(code_1 <= 15):
            money_1 = 300000
        elif(code_1 <= 21):
            money_1 = 100000
        else:
            money_1 = 0
    else:
        money_1 = 0
        
    if((code_2 > 0) and (code_2 < 101)):
        if(code_2 <= 1):
            money_2 = 5120000
        elif(code_2 <= 3):
            money_2 = 2560000
        elif(code_2 <= 7):
            money_2 = 1280000
        elif(code_2 <= 15):
            money_2 = 640000
        elif(code_2 <= 31):
            money_2 = 320000
        else:
            money_2 = 0
    else:
        money_2 = 0
        
    return money_1 + money_2

for _ in range(Case):
    code_1, code_2 = map(int, input().split())
    my_money = check_money(code_1, code_2)
    print(my_money)

'# 코딩 문제 관련 > 파이썬' 카테고리의 다른 글

백준 2748번(python)  (0) 2019.07.31
백준 카카오 코드 페스티벌 예선 15954번(python)  (0) 2019.07.30
백준 10814번(python)  (3) 2019.07.19
백준 11650번(python)  (0) 2019.07.19
백준 1107번(python)  (0) 2019.07.10

Custom data generator를 만들 때는 keras.utils.Sequence 클래스를 상속하는 것으로 시작합니다.

Sequence는 __getitem__, __len__, on_epoch_end, __iter__를 sub method로서 가지고 있습니다.

따라서, 이들을 우리의 데이터에 맞게 변형하여 사용하게 됩니다.


MNIST는 예를 들기 위해 사용했습니다.

import tensorflow as tf
from tensorflow.keras.utils import Sequence
from tensorflow.keras.utils import to_categorical
import numpy as np

mnist = tf.keras.datasets.mnist

(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0

class DataGenerator(Sequence):
    def __init__(self, X, y, batch_size, dim, n_channels, n_classes, shuffle = True):
        self.X = X
        self.y = y if y is not None else y
        self.batch_size = batch_size
        self.dim = dim
        self.n_channels = n_channels
        self.n_classes = n_classes
        self.shuffle = shuffle
        self.on_epoch_end()
        
    def on_epoch_end(self):
        self.indexes = np.arange(len(self.X))
        if self.shuffle:
            np.random.shuffle(self.indexes)
            
    def __len__(self):
        return int(np.floor(len(self.X) / self.batch_size))
    
    def __data_generation(self, X_list, y_list):
        X = np.empty((self.batch_size, *self.dim))
        y = np.empty((self.batch_size), dtype = int)
        
        if y is not None:
            # 지금 같은 경우는 MNIST를 로드해서 사용하기 때문에
            # 배열에 그냥 넣어주면 되는 식이지만,
            # custom image data를 사용하는 경우 
            # 이 부분에서 이미지를 batch_size만큼 불러오게 하면 됩니다. 
            for i, (img, label) in enumerate(zip(X_list, y_list)):
                X[i] = img
                y[i] = label
                
            return X, to_categorical(y, num_classes = self.n_classes)
        
        else:
            for i, img in enumerate(X_list):
                X[i] = img
                
            return X
        
    def __getitem__(self, index):
        indexes = self.indexes[index * self.batch_size : (index + 1) * self.batch_size]
        X_list = [self.X[k] for k in indexes]
        
        if self.y is not None:
            y_list = [self.y[k] for k in indexes]
            X, y = self.__data_generation(X_list, y_list)
            return X, y
        else:
            y_list = None
            X = self.__data_generation(X_list, y_list)
            return X

__data_generation부분을 수정해서 사용하면 됩니다. 원래 같은 경우는 X를 정의할 때, (batch_size, *dim, n_channel)로 정의하나 편의를 위해 지웠습니다. MNIST 데이터셋은 (28, 28, 1)이 아닌 (28, 28)로 인식되기 때문. 필요에 따라 수정하시면 됩니다.


dg = DataGenerator(x_train, y_train, 4, (28, 28), 1, 10)

import matplotlib.pyplot as plt

for i, (x, y) in enumerate(dg):
    if(i <= 1):
        x_first = x[0]
        plt.title(y[0])
        plt.imshow(x_first)

 

 

밑에 나오는 plot들은 IEEE-fraud detection competition과 그 커널을 참조합니다. 

  • sns -> seaborn
  • pd -> pandas
  • plt -> matplotlib.pyplot
  • go -> plotly.graph_objs

subplot간 간격 조정 : plt.subplots_adjust(hspace = num, top = num)

x label 숫자 회전 : plot객체.set_xticklabels(g.get_xticklabels(), rotation = 45)


sns.distplot()


plt.scatter()


sns.countplot()


sns.countplot() + sns.pointplot()


sns.boxenplot()


sns.distplot() + sns.displot()


go.scatter()