larray.Axis¶
-
class
larray.
Axis
(labels, name=None)[source]¶ Represents an axis. It consists of a name and a list of labels.
- Parameters
- labelsarray-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.
- namestr 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
labels
array-like or intlabels of the axis.
- namestr
name of the axis. None in the case of an anonymous axis.
-
__init__
(self, labels, name=None)[source]¶ Initialize self. See help(type(self)) for accurate signature.
Methods
__init__
(self, labels[, name])Initialize self.
align
(self, other[, join])Align axis with other object using specified join method.
all
(self[, name])(Deprecated) Returns a group containing all labels.
apply
(self, func)Returns a new axis with the labels transformed by func.
by
(self, length[, step, template])Split axis into several groups of specified length.
containing
(self, substring)Returns a group with all the labels containing the specified substring.
copy
(self)Returns a copy of the axis.
difference
(self, other)Returns axis with the (set) difference of this axis labels and other labels.
endingwith
(self, suffix)Returns a group with the labels ending with the specified string.
endswith
(\*args, \*\*kwargs)equals
(self, other)Checks if self is equal to another axis.
extend
(self, labels)Append new labels to an axis or increase its length in case of wildcard axis.
group
(self, \*args, \*\*kwargs)ignore_labels
(self)Returns a wildcard axis with the same name and length than this axis.
index
(self, key)Translates a label key to its numerical index counterpart.
insert
(self, new_labels[, before, after])Return a new axis with new_labels inserted before before or after after.
intersection
(self, other)Returns axis with the (set) intersection of this axis labels and other labels.
iscompatible
(self, other)Checks if self is compatible with another axis.
labels_summary
(self)Returns a short representation of the labels.
matches
(\*args, \*\*kwargs)matching
(self[, deprecated, pattern, regex])Returns a group with all the labels matching the specified pattern or regular expression.
rename
(self, name)Renames the axis.
replace
(self, old[, new])Returns a new axis with some labels replaced.
split
(self[, sep, names, regex, return_labels])Split axis and returns a list of Axis.
startingwith
(self, prefix)Returns a group with the labels starting with the specified string.
startswith
(\*args, \*\*kwargs)subaxis
(self, key)Returns an axis for a sub-array.
to_hdf
(self, filepath[, key])Writes axis to a HDF file.
translate
(\*args, \*\*kwargs)union
(self, other)Returns axis with the union of this axis labels and other labels.
Attributes
dtype
Allows to define a subset using positions along the axis instead of labels.
id
iswildcard
labels
labels of the axis.
name