larray.zip_array_items

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

Return a sequence as if simultaneously iterating on several arrays as well as the current iteration “key”.

Broadcasts all values against each other. Scalars are simply repeated.

Parameters
valuesIterable

arrays to iterate on.

axesint, str or Axis or tuple of them, optional

Axis or axes along which to iterate and in which order. 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=b0,b1')
>>> arr2 = ndtest('a=a0,a1;c=c0,c1')
>>> arr1
a\b  b0  b1
 a0   0   1
 a1   2   3
>>> arr2
a\c  c0  c1
 a0   0   1
 a1   2   3
>>> for k, (a1, a2) in zip_array_items((arr1, arr2), 'a'):
...     print("==", k[0], "==")
...     print(a1)
...     print(a2)
== a0 ==
b  b0  b1
    0   1
c  c0  c1
    0   1
== a1 ==
b  b0  b1
    2   3
c  c0  c1
    2   3
>>> for k, (a1, a2) in zip_array_items((arr1, arr2), arr2.c):
...     print("==", k[0], "==")
...     print(a1)
...     print(a2)
== c0 ==
a\b  b0  b1
 a0   0   1
 a1   2   3
a  a0  a1
    0   2
== c1 ==
a\b  b0  b1
 a0   0   1
 a1   2   3
a  a0  a1
    1   3
>>> for k, (a1, a2) in zip_array_items((arr1, arr2)):
...     print(k, "arr1: {}, arr2: {}".format(a1, a2))
(a.i[0], b.i[0], c.i[0]) arr1: 0, arr2: 0
(a.i[0], b.i[0], c.i[1]) arr1: 0, arr2: 1
(a.i[0], b.i[1], c.i[0]) arr1: 1, arr2: 0
(a.i[0], b.i[1], c.i[1]) arr1: 1, arr2: 1
(a.i[1], b.i[0], c.i[0]) arr1: 2, arr2: 2
(a.i[1], b.i[0], c.i[1]) arr1: 2, arr2: 3
(a.i[1], b.i[1], c.i[0]) arr1: 3, arr2: 2
(a.i[1], b.i[1], c.i[1]) arr1: 3, arr2: 3