Labels¶
- class Labels(input_array: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], delim: str = '-')[source][source]¶
A class for storing labels for a LabeledArray.
Examples
>>> Labels(['D21']) @ Labels(['a', 'b', 'c',]) [['D21-a', 'D21-b', 'D21-c']]
- Parameters:
- __add__(other)[source][source]¶
Return (self + other), that is string concatenation, element-wise for a pair of array_likes of str or unicode.
See also
add
- decompose() list[Labels, ...][source][source]¶
Decompose a Labels object into a list of 1d Labels objects.
Examples
>>> Labels(['a-d', 'a-c', 'b-d', 'b-c']).reshape(2,2).decompose() [['a', 'b'], ['d', 'c']] >>> Labels(['a-c-e', 'a-c-f', 'a-d-e', 'a-d-f', 'b-c-e', 'b-c-f', ... 'b-d-e', 'b-d-f']).reshape(2,2,2).decompose() [['a', 'b'], ['c', 'd'], ['e', 'f']] >>> (Labels(['a','b','c']) @ Labels(['d','e','f','g'])).reshape( ... 2,6).decompose() [['a-d-a-e-a-f-a-g-b-d-b-e', 'b-f-b-g-c-d-c-e-c-f-c-g'], ['a-d-b-f'...
- find(value) int | tuple[int][source][source]¶
Get the index of the first instance of a value in the Labels
- join(axis: int = None)[source][source]¶
Join the labels into a single string using the delimiter
- Parameters:
axis (
int, optional) – The axis to join along, by default None
Examples
>>> Labels(['a', 'b', 'c']).join() 'a-b-c' >>> Labels(['a', 'b', 'c']).reshape(1,3).join() 'a-b-c' >>> Labels([['a','b'],['c','d']]).join() 'a-b-c-d' >>> Labels([['a','b'],['c','d']]).join(axis=0) ['a-b', 'c-d'] >>> Labels([['a','b'],['c','d']], '').join(axis=1) ['ac', 'bd']
- split(sep: str = None, maxsplit: int = -1)[source][source]¶
- Return a list of the words in the string, using sep as the delimiter
string.
- sep
The delimiter according which to split the string. None (the default value) means split according to the given delimiter
- maxsplit
Maximum number of splits to do. -1 (the default value) means no limit.
Examples
>>> Labels(['a-b-c', 'd-e-f']).split('-') array([['a', 'b', 'c'], ['d', 'e', 'f']], dtype='<U1') >>> Labels(['a-b-c', 'd-e-f'], '-').split() array([['a', 'b', 'c'], ['d', 'e', 'f']], dtype='<U1')