larray.AxisCollection.index

AxisCollection.index(axis, compatible=False) int[source]

Return the index of axis.

axis can be a name or an Axis object (or an index). If the Axis object itself exists in the list, index() will return it. Otherwise, it will return the index of the local axis with the same name than the key (whether it is compatible or not).

Parameters
axisAxis or int or str

Can be the axis itself or its position (returned if represents a valid index) or its name.

compatiblebool, optional

If axis is an Axis, whether to find an exact match (using Axis.equals) or any compatible axis (using Axis.iscompatible)

Returns
int

Index of the axis.

Raises
ValueError

Raised if the axis is not present.

Examples

>>> age = Axis(range(20), 'age')
>>> sex = Axis('sex=M,F')
>>> time = Axis([2007, 2008, 2009, 2010], 'time')
>>> col = AxisCollection([age, sex, time])
>>> col.index(time)
2
>>> col.index('sex')
1