next up previous contents
Next: labelUsing Up: Integrated Methods Previous: Integrated Methods   Contents

subset

The Labelings method is a static method of the Labeling class. By passing in a Dataset, Labeling and a label or list of labels, it will return a SubsetView which contains the subset or rows and/or columns labeled by the particular label(s) chosen. If the labels only labels rows or columns, then all of the columns or rows, respectively, will remain intact. If the label labels both rows and columns, then the view returned will be the intersection of the rows and columns.

More appropriately, this method may be thought of as creating a subset from a Labeling and labels(s). While it may seem simple, subsetting Dataset in this manner can be quite convenient. Let's try.

>>> from compClust.mlx.datasets import Dataset
>>> from compClust.mlx.labelings import *
>>> import MLab
>>> ds = Dataset(MLab.rand(15,5))
>>> labels = Labeling(ds)
>>> labels.addLabelToRows('x',[1,3,4,6,8])
>>> labels.addLabelToCols('y',[1,2,3])
>>> labels.addLabelToRows('z',[1,2,5,7,9,10])
>>> labels.addLabelToCols('z',[0,1,4])
>>> subset1 = subsetByLabeling(ds, labels, 'x')
>>> subset2 = subsetByLabeling(ds, labels, 'y')
>>> subset3 = subsetByLabeling(ds, labels, 'z')
>>> subset4 = subsetByLabeling(ds, labels, '')
>>> subset1
RowSubsetView: None, 5 by 5
>>> subset2
ColumnSubsetView: None, 15 by 3
>>> subset3
ColumnSubsetView: None, 6 by 3
>>> subset4
Dataset: None, 0 by 0

As you see, the subset returned matches the rows and columns specified in the Labeling. Also, when no rows were specified, all of the rows were returned, and the same for columns. Notice also, that creating a subset from non-existent label results in an empty Dataset.


next up previous contents
Next: labelUsing Up: Integrated Methods Previous: Integrated Methods   Contents
Lucas Scharenbroich 2003-08-27