Skip to content

Instantly share code, notes, and snippets.

View benjaminkaplanphd's full-sized avatar

Benjamin Kaplan benjaminkaplanphd

View GitHub Profile
@benjaminkaplanphd
benjaminkaplanphd / explode.py
Created February 6, 2019 18:06
Explode array values in columns to multiple rows
import numpy as np
import pandas as pd
def explode(frame: pd.DataFrame, columns: List[str]):
"""
This helper function explodes a new row
for each value in an array of values.
If there is more than one column to be exploded,
the array lengths must be the same (row-wise)
@benjaminkaplanphd
benjaminkaplanphd / theano_shape.py
Created September 13, 2019 15:12
Print Theano Tensor Shape
import numpy as np
from theano import function, printing, shared, tensor as T
PRINT = printing.Print('Theano shape: ', attrs=['shape'])
def example():
array = np.ones((3, 4))
print(f'Numpy shape: {array.shape}')