Skip to content

Instantly share code, notes, and snippets.

View dnnagy's full-sized avatar

Nagy Dániel dnnagy

  • Wigner Research Centre for Physics
  • Budapest
  • 08:41 (UTC +02:00)
View GitHub Profile
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'
from datetime import datetime
xx = '2018-01-01 00:30'
dt = datetime.strptime(xx, "%Y-%m-%d %H:%M")
dt.timestamp() # 1514766600.0
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.
"{:,}".format(1234567890) # => '1,234,567,890'
int('1,234,567,890'.replace(',',"")) # => 1234567890
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)
import time
## 24 hour format ##
def print_t(str_):
print( "[" + time.strftime("%Y-%m-%d %H:%M:%S") + "] " + str(str_))
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']
def find_nearest_index(array, value):
array = np.asarray(array)
idx = (np.abs(array - value)).argmin()
return idx
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])
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])