View idCard.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def calcId(digit): | |
if not isinstance(digit, int) or len(str(digit)) != 17: | |
return False | |
table = '10X123456789' | |
alpha = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2] | |
return table[sum([int(x)*a for x, a in zip(str(digit), alpha)]) % 11] | |
def isGoodId(instr): |
View permutation_combination.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def permutation(array): | |
if len(array) == 1: | |
return [array] | |
output = [] | |
for i in range(len(array)): | |
if i == len(array) - 1: | |
remain = array[0:i] | |
else: | |
remain = array[0:i] + array[i+1:] | |
for back in permutation(remain): |
View lawofcosine.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
method_list = [1, 2, 3] | |
for method in method_list: | |
for i in range(2000): | |
length = 10000 | |
a = np.random.randn(length).astype(np.float32) | |
b = np.random.randn(length).astype(np.float32) | |
# non-stable when theta is small |
View image_data_augmentation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import shutil | |
from math import ceil, floor | |
import numpy as np | |
import cv2 | |
""" | |
Data augmentation. | |
""" |
View em.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
SIGMA = 1 | |
def gauss(x, mu, sigma, eps=1e-8): | |
return 1./np.sqrt(np.pi*2*sigma**2+eps) * np.exp(-(x-mu)**2/(2*sigma**2+eps)) | |
def gauss_vec(x, mu, sigma, eps=1e-8): | |
""" x: Nx1 |
View show_score.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
from mpl_toolkits.mplot3d import Axes3D | |
def f1_score(precision, recall): | |
return precision*recall/(precision+recall) | |
x = np.arange(1e-3, 1, 1e-3) | |
y = np.arange(1e-3, 1, 1e-3) | |
X, Y = np.meshgrid(x, y) |