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
labelsarray-like or int

Labels of the axis.

namestr

name of the axis. None in the case of an anonymous axis.

__init__(labels, name=None)[source]

Methods

__init__(labels[, name])

align(other[, join])

Align axis with other object using specified join method.

all([name])

(Deprecated) Return a group containing all labels.

apply(func)

Return a new axis with the labels transformed by func.

astype(dtype[, casting])

Cast labels to a specified type.

by(length[, step, template])

Split axis into several groups of specified length.

containing(substring)

Return a group with all the labels containing the specified substring.

copy()

Return a copy of the axis.

difference(other)

Return axis with the (set) difference of this axis labels and other labels.

endingwith(suffix)

Return a group with the labels ending with the specified string.

endswith(**kwargs)

equals(other)

Check if this axis is equal to another axis.

extend(labels)

Append new labels to an axis or increase its length in case of wildcard axis.

group(*args[, name])

ignore_labels()

Return a wildcard axis with the same name and length than this axis.

index(key)

Translate 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)

Return axis with the (set) intersection of this axis labels and other labels.

iscompatible(other)

Check if this axis is compatible with another axis.

labels_summary()

Return a short representation of the labels.

matches(**kwargs)

matching([deprecated, pattern, regex])

Return a group with all the labels matching the specified pattern or regular expression.

max()

Get maximum of labels.

min()

Get minimum of labels.

rename(name)

Rename the axis.

replace(old[, new])

Return a new axis with some labels replaced.

split([sep, names, regex, return_labels])

Split axis and returns a list of Axis.

startingwith(prefix)

Return a group with the labels starting with the specified string.

startswith(**kwargs)

subaxis(key)

Return an axis for a sub-array.

to_hdf(filepath[, key])

Write axis to a HDF file.

translate(**kwargs)

union(other)

Return axis with the union of this axis labels and other labels.

Attributes

name

dtype

i

Take a subset using positions along the axis instead of labels.

id

iswildcard

labels

Labels of the axis.