Mercurial > pylearn
view sparse_instance.py @ 530:844bad76459c
replaced the use of removed function compile.eval_outputs with theano.function.
author | Frederic Bastien <bastienf@iro.umontreal.ca> |
---|---|
date | Mon, 17 Nov 2008 14:18:28 -0500 |
parents | 217c8789284b |
children |
line wrap: on
line source
""" Sparse instances. Each instance is represented as dict with key dimension. Dimensions not present in the dict have value 0. """ from numpy import zeros def to_vector(instances, dimensions): """ Convert sparse instances to vectors. @type instances: list of sparse instances @param dimensions: The number of dimensions in each instance. @rtype: numpy matrix (instances x dimensions) @todo: Allow this function to convert SINGLE instances (not lists). """ v = zeros((len(instances), dimensions)) l = len(instances) for i in range(l): for idx in instances[i].keys(): v[i][idx] = instances[i][idx] return v