import string
import random
import time
import functools
def list_from_2d_np(np_array):
"""
convert a 2d numpy array to a list
"""
shape = np_array.shape
total = shape[0] * shape[1]
new_array = np_array.reshape(total)
return list(new_array)
def generate_random_str(length=20):
return ''.join(random.choice(string.digits + string.ascii_letters) for _ in range(length))
def generate_time_stamp():
time_unique_id = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())
return time_unique_id
def time_it(fn):
@functools.wraps(fn)
def inner(*args, **kwargs):
start = time.time()
fn(*args, **kwargs)
end = time.time()
print("Time cost for function `{}`: {}".format(fn.__name__, (end - start)))
return inner