Movatterモバイル変換


[0]ホーム

URL:


SciPy

numpy.nested_iters

numpy.nested_iters()

Create nditers for use in nested loops

Create a tuple ofnditer objects which iterate in nested loops overdifferent axes of the op argument. The first iterator is used in theoutermost loop, the last in the innermost loop. Advancing one will changethe 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)

Seenditer parameters of the same name

Returns:
iters:tuple of nditer

An nditer for each item inaxes, outermost first

See also

nditer

Examples

Basic usage. Note how y is the “flattened” version of[a[:, 0, :], a[:, 1, 0], a[:, 2, :]] since we specifiedthe first iter’s axes as [1]

>>>a=np.arange(12).reshape(2,3,2)>>>i,j=np.nested_iters(a,[[1],[0,2]],flags=["multi_index"])>>>forxini:...print(i.multi_index)...foryinj:...print('',j.multi_index,y)
(0,)
(0, 0) 0(0, 1) 1(1, 0) 6(1, 1) 7
(1,)
(0, 0) 2(0, 1) 3(1, 0) 8(1, 1) 9
(2,)
(0, 0) 4(0, 1) 5(1, 0) 10(1, 1) 11

Previous topic

numpy.ndindex.next

Next topic

numpy.flatiter

Quick search

  • © Copyright 2008-2018, The SciPy community.
  • Last updated on Jul 24, 2018.
  • Created usingSphinx 1.6.6.

[8]ページ先頭

©2009-2025 Movatter.jp