Skip to content

Instantly share code, notes, and snippets.

15 06
16 06
20 06
01 07
02 07
03 07
04 07
05 07
06 07
07 07
@tmramalho
tmramalho / grid.py
Created October 26, 2018 09:37
Show a 4D numpy array as a 2D image
def image_grid(data, n_cols=None, zoom=1):
if n_cols is None:
n_cols = int(np.ceil(np.sqrt(data.shape[0])))
n_rows = int(np.ceil(data.shape[0]/n_cols))
target = np.zeros((data.shape[1]*n_rows, data.shape[2]*n_cols, data.shape[3]), dtype=data.dtype)
flat_data = data.swapaxes(1,2).reshape((data.shape[0]*data.shape[1], data.shape[2], data.shape[3])).swapaxes(0, 1)
for i in range(n_rows):
start_y = i*data.shape[2]*n_cols
end_y = (i+1)*data.shape[2]*n_cols
start_x = i*data.shape[1]
@tmramalho
tmramalho / Digits analysis
Created April 12, 2015 18:22
Factor analysis and PCA blog post
import numpy as np
import matplotlib.pyplot as plt
from sklearn.decomposition import PCA, FactorAnalysis, SparsePCA
from sklearn import datasets
dset = datasets.load_digits()
x = dset.data
y = dset.target
model = PCA(n_components=2)
import theano
import theano.tensor as T
import numpy as np
import cPickle
import random
import matplotlib.pyplot as plt
class RNN(object):
def __init__(self, nin, n_hidden, nout):