Skip to content

Instantly share code, notes, and snippets.

View Kcrong's full-sized avatar
🇰🇷
Smile

Henry Kim Kcrong

🇰🇷
Smile
View GitHub Profile
@Kcrong
Kcrong / auto_comp.py
Created April 16, 2018 06:16
세 수를 받고, 대소 관계를 >, ==, < 등의 기호로 보여주는 코드
ai = input('num 1: ')
bi = input('num 2: ')
ci = input('num 3: ')
inp = sorted([ai, bi, ci])
operators = ['>', '==', '<']
def exp_c(a, b, op):
return eval("{} {} {}".format(a, op, b))
# with for loop
# range() --> starts from 0
def with_for_loop():
for i in range(10):
print('Hit %d times' % (i+1))
print('The tree fell down!!')
def with_while_loop():
hit = 0
def seq2dataset(seq, window_size):
dataset = []
for i in range(len(seq)-window_size):
subset = seq[i:(i+window_size+1)]
dataset.append([code2idx[item] for item in subset])
return np.array(dataset)
code2idx = {'c4':0, 'd4':1, 'e4':2, 'f4':3, 'g4':4, 'a4':5, 'b4':6,
'c8':7, 'd8':8, 'e8':9, 'f8':10, 'g8':11, 'a8':12, 'b8':13}
idx2code = {0:'c4', 1:'d4', 2:'e4', 3:'f4', 4:'g4', 5:'a4', 6:'b4',
7:'c8', 8:'d8', 9:'e8', 10:'f8', 11:'g8', 12:'a8', 13:'b8'}
# Or use dict comprehension
idx2code = {v: k for k, v in code2idx.items()}
# Whole data
seq = ['g8', 'e8', 'e4', 'f8', 'd8', 'd4', 'c8', 'd8', 'e8', 'f8', 'g8', 'g8', 'g4',
'g8', 'e8', 'e8', 'e8', 'f8', 'd8', 'd4', 'c8', 'e8', 'g8', 'g8', 'e8', 'e8', 'e4',
'd8', 'd8', 'd8', 'd8', 'd8', 'e8', 'f4', 'e8', 'e8', 'e8', 'e8', 'e8', 'f8', 'g4',
'g8', 'e8', 'e4', 'f8', 'd8', 'd4', 'c8', 'e8', 'g8', 'g8', 'e8', 'e8', 'e4']
http://tykimos.github.io/warehouse/2017-3-8_CNN_Getting_Started_handwriting_shape.zip
6 148 72 35 0 33.6 0.627 50 1
1 85 66 29 0 26.6 0.351 31 0
8 183 64 0 0 23.3 0.672 32 1
1 89 66 23 94 28.1 0.167 21 0
0 137 40 35 168 43.1 2.288 33 1
5 116 74 0 0 25.6 0.201 30 0
3 78 50 32 88 31.0 0.248 26 1
10 115 0 0 0 35.3 0.134 29 0
2 197 70 45 543 30.5 0.158 53 1
8 125 96 0 0 0.0 0.232 54 1
from keras.utils import np_utils
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense, Activation
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train = x_train.reshape(x_train.shape[0], 784).astype('float32') / 255.0
x_test = x_test.reshape(x_test.shape[0], 784).astype('float32') / 255.0
y_train = np_utils.to_categorical(y_train)
y_test = np_utils.to_categorical(y_test)
"""
1. main 함수에서 `async def A`를 호출 후 await 하고, 반환값을 받아 다시 `async def B`를 호출하는 방식
"""
import asyncio
from socket import socket, AF_INET, SOCK_STREAM
@Kcrong
Kcrong / script.py
Created July 7, 2017 08:39
Excel to dict
import json
import pandas as pd
from collections import defaultdict
multi_depth_defaultdict = lambda: defaultdict(multi_depth_defaultdict)
df = pd.read_excel('category.xlsx')
data = multi_depth_defaultdict()