You are viewing an older version (2.4.3). Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy 2.4.3 / numpy / nested_iters

built-in

numpy:nested_iters

Signature

built-in nested_iters ( op axes flags = None op_flags = None op_dtypes = None order = K casting = safe buffersize = 0 )

Summary

Create nditers for use in nested loops

Extended Summary

Create a tuple of nditer objects which iterate in nested loops over different axes of the op argument. The first iterator is used in the outermost loop, the last in the innermost loop. Advancing one will change the subsequent iterators to point at its new element.

Parameters

op : ndarray or sequence of array_like

The array(s) to iterate over.

axes : list of list of int

Each item is used as an "op_axes" argument to an nditer

flags, op_flags, op_dtypes, order, casting, buffersize (optional)

See nditer parameters of the same name

Returns

iters : tuple of nditer

An nditer for each item in axes, outermost first

Examples

Basic usage. Note how y is the "flattened" version of [a[:, 0, :], a[:, 1, 0], a[:, 2, :]] since we specified the first iter's axes as [1]
import numpy as np
a = np.arange(12).reshape(2, 3, 2)
i, j = np.nested_iters(a, [[1], [0, 2]], flags=["multi_index"])
for x in i:
     print(i.multi_index)
     for y in j:
         print('', j.multi_index, y)

See also

nditer

Aliases

  • numpy.nested_iters