/usr/lib/python2.7/dist-packages/dipy/core/ndindex.py is in python-dipy 0.10.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | from __future__ import division, print_function, absolute_import
import numpy as np
from numpy.lib.stride_tricks import as_strided
def ndindex(shape):
"""
An N-dimensional iterator object to index arrays.
Given the shape of an array, an `ndindex` instance iterates over
the N-dimensional index of the array. At each iteration a tuple
of indices is returned; the last dimension is iterated over first.
Parameters
----------
shape : tuple of ints
The dimensions of the array.
Examples
--------
>>> from dipy.core.ndindex import ndindex
>>> shape = (3, 2, 1)
>>> for index in ndindex(shape):
... print(index)
(0, 0, 0)
(0, 1, 0)
(1, 0, 0)
(1, 1, 0)
(2, 0, 0)
(2, 1, 0)
"""
if len(shape) == 0:
yield ()
else:
x = as_strided(np.zeros(1), shape=shape, strides=np.zeros_like(shape))
try:
ndi = np.nditer(x, flags=['multi_index', 'zerosize_ok'], order='C')
except AttributeError:
# nditer only available in numpy >= 1.6
for ix in np.ndindex(*shape):
yield ix
else:
for e in ndi:
yield ndi.multi_index
|