[Numpy-discussion] nditer: possible to manually handle dimensions with different lengths?
jsalvati at u.washington.edu
Fri Sep 30 11:03:40 EDT 2011
Using nditer, is it possible to manually handle dimensions with different
For example, lets say I had an array A[5, 100] and I wanted to sample every
10 along the second axis so I would end up with an array B[5,10]. Is it
possible to do this with nditer, handling the iteration over the second axis
manually of course (probably in cython)?
I want something like this (modified from
cdef np.ndarray[double] x
cdef np.ndarray[double] y
cdef int size
cdef double value
cdef int j
axeslist = list(arr.shape)
axeslist = -1
out = zeros((arr.shape, 10))
it = np.nditer([arr, out], flags=['reduce_ok', 'external_loop',
op_flags=[['readonly'], ['readwrite', 'no_broadcast']],
it.operands[...] = 0
for xarr, yarr in it:
x = xarr
y = yarr
size = x.shape
j = 0
for i in range(size):
#some magic here involving indexing into x[i] and y[j]
Does this make sense? Is it possible to do?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion