def filter_labels(train, label, classes=None):
    if isinstance(train, theano.tensor.sharedvar.SharedVariable):
        train = train.get_value(borrow=True)
    if isinstance(label, theano.tensor.sharedvar.SharedVariable):
        label = label.get_value(borrow=True)

    if not (isinstance(train, numpy.ndarray) or scipy.sparse.issparse(train)):
        raise TypeError('train must be a numpy array, a scipy sparse matrix,'
                        ' or a theano shared array')

    # Examples for which any label is set
    if classes is not None:
        label = label[:, classes]

    # Special case for sparse matrices
    if scipy.sparse.issparse(train):
        idx = label.sum(axis=1).nonzero()[0]
        return (train[idx], label[idx])

    # Compress train and label arrays according to condition
    condition = label.any(axis=1)
    return tuple(var.compress(condition, axis=0) for var in (train, label))
Filter examples of train for which we have labels
dataset/ETHPy150Open lisa-lab/pylearn2/pylearn2/utils/datasets.py/filter_labels