Skip to content

Instantly share code, notes, and snippets.

View MSWon's full-sized avatar

Minsub Won MSWon

View GitHub Profile
@MSWon
MSWon / max_increase_seq.py
Created June 23, 2019 13:54
최장증가수열 백준 2352번 반도체 설계 알고리즘 문제
N = int(input())
input_num = input().split(" ")
input_num = [int(num) for num in input_num]
def change(result_list, num):
for i in range(len(result_list)-1,-1,-1):
if(result_list[i] > num):
idx = i
else:
break
@MSWon
MSWon / duplicate_symbol.py
Created June 15, 2019 03:51
get rid of duplicate symbol using regular expression
import re
line = "I don't go to school--with you ========== ------------ ........ *******"
re.sub(r"(\W)\1+", r"\1" , line)
@MSWon
MSWon / tensor_slice_positions.py
Last active June 15, 2019 14:12
Slicing input tensor by its positions
import tensorflow as tf
import numpy as np
input_data = np.random.rand(10, 10, 64)
positions = [0,9,8,2,3,5,1,2,4,6]
input_tensor = tf.placeholder(shape = (None,10,64) , dtype = tf.float32)
positions_tensor = tf.placeholder(shape = (None,) , dtype = tf.int32)
@MSWon
MSWon / total_cases.py
Created June 11, 2019 08:05
getting all possible cases
x = [1,2,3,4,5,6,7,8,9,10]
total_case = []
for i in x:
first = [i]
for j in x:
c_first = list(first)
if(i < j):
c_first.append(j)
@MSWon
MSWon / tf_selfattention_mask_diag.py
Created May 7, 2019 07:30
tf selfattention mask with diag zero value
import tensorflow as tf
max_seq_len = 6
seq_len = [3,5,4]
row_vector = tf.range(0,max_seq_len,1) ## [, max_seq_len]
matrix = tf.cast(tf.expand_dims(seq_len,-1), tf.int32) ## [batch_size, 1]
t = tf.cast(row_vector < matrix, tf.float32) ## [batch_size, max_seq_len]
t = tf.expand_dims(t, -1) ## [batch_size, max_seq_len, 1]
@MSWon
MSWon / Channelwise_SelfAttention.py
Last active April 16, 2019 12:55
Channelwise_SelfAttention
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 6 10:47:30 2019
@author: jbk48
"""
from keras.layers import Layer
import tensorflow as tf
@MSWon
MSWon / scatter_update.py
Created March 12, 2019 08:13
padding zero vector not trainable via scatter_update
import tensorflow as tf
g = tf.Graph()
with g.as_default():
a = tf.Variable(initial_value=[[1, 2, 4, 0],[2, 4, 5, 8]])
b = tf.scatter_update(a, [0], [[0, 0, 0, 0]])
with tf.Session(graph=g) as sess:
sess.run(tf.initialize_all_variables())
print(sess.run(a))
@MSWon
MSWon / padding_example.py
Last active March 9, 2019 14:31
padding with max seq len
import numpy as np
import tensorflow as tf
batch_size = 3
max_seq_len = 5
dim = 4
input_data = tf.placeholder(shape = (None,max_seq_len,dim), dtype = tf.float32)
seq_len = tf.placeholder(shape = [None], dtype = tf.int32)
@MSWon
MSWon / tf.where_example.py
Created January 19, 2019 15:46
tf.where_example
import tensorflow as tf
# Constants (3-element arrays).
a = tf.constant([100, 200, 300])
b = tf.constant([1, 2, 3])
# Use placeholder for predicate to where.
# ... We pass in an array of 3 bools to fill the placeholder.
j = tf.placeholder(tf.bool, [3])
@MSWon
MSWon / shuffle_list.py
Created January 8, 2019 10:33
shuffle two list in same order
import random
a = ['a', 'b', 'c']
b = [1, 2, 3]
c = list(zip(a, b))
random.shuffle(c)
a, b = zip(*c)