For our purposes, we'll create our familiar random 3 by 3 matrix and create a Labeling attached to it.
>>> from compClust.mlx.labelings import * >>> ds = Dataset(MLab.rand(3,3)) >>> lab = Labeling(ds) >>> lab Labeling: None, 0 unique labels
The Labeling is instantiated bound to the particular dataset instance. Inspecting the Labeling shows that it has no name and zero unique labels. This shouldn't be surprising since we haven't added any labels yet.
As a first step, let's give the labeling a proper name.
>>> lab.setName('My Labeling') >>> lab.getName() 'My Labeling' >>> lab Labeling: My Labeling, 0 unique labels
If we look at the dataset's list of current Labeling we can see the name of our new Labeling. To remove the Labeling from the Dataset we use the removeLabeling() method. This is analogous to the removeView() method for removing View, and the reasoning behind it is the same - the interaction between Dataset and Labeling is complicated in that it introduces circular references which must be explicitly broken. Let's remove the Labeling now.
>>> ds.getLabelings() [Labeling: My Labeling, 0 unique labels] >>> ds.removeLabeling(lab) >>> ds.getLabelings() []
As with View we can retrieve Labeling by name for referencing and deleting. To try this, let's quickly create, name and remove a Labeling from the dataset.
>>> lab = Labeling(ds) >>> lab.setName('foo') >>> ds.getLabelings() [Labeling: foo, 0 unique labels] >>> ds.removeLabeling(ds.getLabeling('foo')) >>> ds.getLabelings() []
This completes the range of use for instantiating and removing Labeling. Now let's do some real work with them!