Mercurial > pylearn
view pylearn/sandbox/sparse_instance.py @ 1531:88f361283a19 tip
Fix url/name to pylearn2.
author | Frederic Bastien <nouiz@nouiz.org> |
---|---|
date | Mon, 09 Sep 2013 10:08:05 -0400 |
parents | b054271b2504 |
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