This file contains hidden or 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 | |
from matplotlib import pyplot as plt | |
# Set up dark color theme | |
plt.rcParams['axes.facecolor'] = '#323A48' | |
plt.rcParams['axes.edgecolor'] = '#92A2BD' | |
plt.rcParams['figure.facecolor'] = '#323A48' | |
plt.rcParams['savefig.facecolor'] = '#323A48' | |
plt.rcParams['text.color'] = '#DBE1EA' | |
plt.rcParams['axes.labelcolor'] = '#DBE1EA' |
This file contains hidden or 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
from datetime import datetime | |
xx = '2018-01-01 00:30' | |
dt = datetime.strptime(xx, "%Y-%m-%d %H:%M") | |
dt.timestamp() # 1514766600.0 |
This file contains hidden or 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 generate_batches(X, y, batch_size, shuffle=False, random_state=None, return_dropped=True): | |
X_batches = X | |
y_batches = y | |
nDrop = len(X)%batch_size | |
# This function only shuffles the array along the first axis | |
# of a multi-dimensional array. The order of sub-arrays is | |
# changed but their contents remains the same. |
This file contains hidden or 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
"{:,}".format(1234567890) # => '1,234,567,890' | |
int('1,234,567,890'.replace(',',"")) # => 1234567890 |
This file contains hidden or 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 keras | |
from keras import Sequential | |
from keras.models import Sequential | |
from keras.models import Model | |
from keras.layers import Input, Dense, LSTM, Concatenate, Flatten | |
from keras.optimizers import SGD | |
from keras.layers.normalization import BatchNormalization | |
np.random.seed(42) |
This file contains hidden or 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 time | |
## 24 hour format ## | |
def print_t(str_): | |
print( "[" + time.strftime("%Y-%m-%d %H:%M:%S") + "] " + str(str_)) |
This file contains hidden or 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 split_scientific_float(n_prec, _f): | |
v=('{:.'+str(n_prec)+'g}').format(_f).split('e') | |
if len(v)==1: v.append(0) | |
return v | |
split_scientific_float(5, 4.311237638482733e-91) # Output: ['4.3112', '-91'] |
This file contains hidden or 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 find_nearest_index(array, value): | |
array = np.asarray(array) | |
idx = (np.abs(array - value)).argmin() | |
return idx |
This file contains hidden or 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 arrayToLatexRow(a): | |
ns = [] | |
for n in a: | |
ns.append("${0}$".format(n)) | |
ns = ' & '.join(ns) | |
ns = ns + " \\ \hline" | |
return ns | |
tauarr = np.array([0.00325, 0.00228, 0.00253, 0.00284, 0.00272, 0.00272]) |
This file contains hidden or 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 latexRowToArray(s): | |
nums = s.split("&") | |
for k in range(len(nums)): | |
nums[k] = ''.join([i for i in nums[k] if i.isdigit() or i in ['.']]) | |
nums[k] = float(nums[k]) | |
return np.array(nums) | |
taus = '$0.00325$ & $0.00228$ & $0.00253$ & $0.00284$ & $0.00272$ & $0.00272$ \\ \hline' | |
latexRowToArray(taus) | |
#output: array([0.00325, 0.00228, 0.00253, 0.00284, 0.00272, 0.00272]) |