Skip to content

Instantly share code, notes, and snippets.

Avatar

Benjamin Kaplan benjaminkaplanphd

View GitHub Profile
@benjaminkaplanphd
benjaminkaplanphd / theano_shape.py
Created Sep 13, 2019
Print Theano Tensor Shape
View theano_shape.py
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}')
@benjaminkaplanphd
benjaminkaplanphd / explode.py
Created Feb 6, 2019
Explode array values in columns to multiple rows
View explode.py
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)