larray.Array.values
- Array.values(axes=None, ascending=True) Union[ndarray, List[Array], ArrayPositionalIndexer] [source]
Return a view on the values of the array along axes.
- Parameters
- axesint, str or Axis or tuple of them, optional
Axis or axes along which to iterate and in which order. Defaults to None (all axes in the order they are in the array).
- ascendingbool, optional
Whether to iterate the axes in ascending order (from start to end). Defaults to True.
- Returns
- Sequence
An object you can iterate (loop) on and index by position.
Examples
>>> arr = ndtest((2, 2)) >>> arr a\b b0 b1 a0 0 1 a1 2 3
By default it iterates on all axes, in the order they are in the array.
>>> for value in arr.values(): ... print(value) 0 1 2 3 >>> for value in arr.values(ascending=False): ... print(value) 3 2 1 0
but you can specify another axis order:
>>> for value in arr.values(('b', 'a')): ... print(value) 0 2 1 3
When you specify less axes than the array has, you get arrays back:
>>> # iterate on the "b" axis, that is return the (sub)array for each label along the "b" axis ... for value in arr.values('b'): ... print(value) a a0 a1 0 2 a a0 a1 1 3 >>> # iterate on the "b" axis, that is return the (sub)array for each label along the "b" axis ... for value in arr.values('b', ascending=False): ... print(value) a a0 a1 1 3 a a0 a1 0 2
One can also access elements of the value sequence directly, instead of iterating over it. Say we want to retrieve the first and last values of our array, we could write:
>>> values = arr.values() >>> values[0] 0 >>> values[-1] 3