larray.zip_array_values

larray.zip_array_values(values, axes=None, ascending=True) SequenceZip[source]

Return a sequence as if simultaneously iterating on several arrays.

Parameters
valuessequence of (scalar or Array)

Values to iterate on. Scalars are repeated as many times as necessary.

axesint, str or Axis or tuple of them, optional

Axis or axes along which to iterate and in which order. All those axes must be compatible (if present) between the different values. Defaults to None (union of all axes present in all arrays, in the order they are found).

ascendingbool, optional

Whether to iterate the axes in ascending order (from start to end). Defaults to True.

Returns
Sequence

Examples

>>> arr1 = ndtest('a=a0,a1;b=b1,b2')
>>> arr2 = ndtest('a=a0,a1;c=c1,c2')
>>> arr1
a\b  b1  b2
 a0   0   1
 a1   2   3
>>> arr2
a\c  c1  c2
 a0   0   1
 a1   2   3
>>> for a1, a2 in zip_array_values((arr1, arr2), 'a'):
...     print("==")
...     print(a1)
...     print(a2)
==
b  b1  b2
    0   1
c  c1  c2
    0   1
==
b  b1  b2
    2   3
c  c1  c2
    2   3

When the axis to iterate on (c in this case) is not present in one of the arrays (arr1), that array is repeated for each label of that axis:

>>> for a1, a2 in zip_array_values((arr1, arr2), arr2.c):
...     print("==")
...     print(a1)
...     print(a2)
==
a\b  b1  b2
 a0   0   1
 a1   2   3
a  a0  a1
    0   2
==
a\b  b1  b2
 a0   0   1
 a1   2   3
a  a0  a1
    1   3

When no axes are given, it iterates on the union of all compatible axes (a, b, and c in this case):

>>> for a1, a2 in zip_array_values((arr1, arr2)):
...     print(f"arr1: {a1}, arr2: {a2}")
arr1: 0, arr2: 0
arr1: 0, arr2: 1
arr1: 1, arr2: 0
arr1: 1, arr2: 1
arr1: 2, arr2: 2
arr1: 2, arr2: 3
arr1: 3, arr2: 2
arr1: 3, arr2: 3