Skip to content

Instantly share code, notes, and snippets.

View harshitcodes's full-sized avatar

Harshit Tyagi harshitcodes

View GitHub Profile
def record_comp_time(func_list, data_list, rep=3, number=1):
''' Function to compare the performance of different functions.
Args:
func_list : list
list with function names as strings
data_list : list
list with data set names as strings
rep : int
number of repetitions of the whole comparison
number : int
import numpy as np
from random import gauss
path = '<enter the path where you want to write the file>'
a1 = [gauss(1.5, 2) for i in range(1000000)]
import pickle
pkl_file = open(path + "serialized_data.pkl", 'wb')
%time pickle.dump(a1, pkl_file)
filename = '<path to your folder>' + 'tab.h5'
h5 = tb.open_file(filename, 'w')
# creating 2million rows for the database
rows = 2000000
table_model = {
'Num1': tb.IntCol(pos=1),
'Num2': tb.IntCol(pos=2)
}
filters = tb.Filters(complevel=0) # no compression
ran_int = np.random.randint(0, 10000, size=(rows, 2))
# rows to be written one by one
for i in range(rows):
pointer['Num1'] = ran_int[i, 0]
pointer['Num2'] = ran_int[i, 1]
pointer.append()
# this appends the data and
# moves the pointer one row forward
tab.flush()
class NeuralNet:
def __init__(self, x, y):
self.input = x
self.y = y
self.weights1 = np.random.rand(self.input.shape[1],4)
self.weights2 = np.random.rand(4,1)
self.output = np.zeros(y.shape)
CREATE OR REPLACE TABLE ecommerce_analytics.subset_user_sessions
OPTIONS(
description="Obfuscated data from Google merchandise store"
) AS
SELECT * FROM `next-marketing-analytics.ecommerce.all_sessions_raw`
WHERE date = '20170101';