larray.Axis¶
-
class
larray.Axis(labels, name=None)[source]¶ Represents an axis. It consists of a name and a list of labels.
Parameters: labels : array-like or int
collection of values usable as labels, i.e. numbers or strings or the size of the axis. In the last case, a wildcard axis is created.
name : str or Axis, optional
name of the axis or another instance of Axis. In the second case, the name of the other axis is simply copied. By default None.
Examples
>>> gender = Axis(['M', 'F'], 'gender') >>> gender Axis(['M', 'F'], 'gender') >>> gender.name 'gender' >>> list(gender.labels) ['M', 'F']
using a string definition
>>> gender = Axis('gender=M,F') >>> gender Axis(['M', 'F'], 'gender') >>> age = Axis('age=0..9') >>> age Axis([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 'age') >>> code = Axis('code=A,C..E,F..G,Z') >>> code Axis(['A', 'C', 'D', 'E', 'F', 'G', 'Z'], 'code')
a wildcard axis only needs a length
>>> row = Axis(10, 'row') >>> row Axis(10, 'row') >>> row.labels array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
axes can also be defined without name
>>> anonymous = Axis('0..4') >>> anonymous Axis([0, 1, 2, 3, 4], None)
Attributes
labelslabels of the axis. name (str) name of the axis. None in the case of an anonymous axis. Methods
__init__(labels[, name])align(other[, join])Align axis with other object using specified join method. all([name])(Deprecated) Returns a group containing all labels. by(length[, step])Split axis into several groups of specified length. containing(substring)Returns a group with all the labels containing the specified substring. copy()Returns a copy of the axis. difference(other)Returns axis with the (set) difference of this axis labels and other labels. endingwith(suffix)Returns a group with the labels ending with the specified string. endswith(*args, **kwargs)equals(other)Checks if self is equal to another axis. extend(labels)Append new labels to an axis or increase its length in case of wildcard axis. group(*args, **kwargs)index(key[, bool_passthrough])Translates a label key to its numerical index counterpart. insert(new_labels[, before, after])Return a new axis with new_labels inserted before before or after after. intersection(other)Returns axis with the (set) intersection of this axis labels and other labels. iscompatible(other)Checks if self is compatible with another axis. labels_summary()Returns a short representation of the labels. matches(*args, **kwargs)matching(pattern)Returns a group with all the labels matching the specified pattern (regular expression). rename(name)Renames the axis. replace(old[, new])Returns a new axis with some labels replaced. split([sep, names, regex, return_labels])Split axis and returns a list of Axis. startingwith(prefix)Returns a group with the labels starting with the specified string. startswith(*args, **kwargs)subaxis(key[, name])Returns an axis for a sub-array. translate(*args, **kwargs)union(other)Returns axis with the union of this axis labels and other labels.