Note that there are some explanatory texts on larger screens.

plurals
  1. POnditer: possible to manually handle dimensions with different lengths?
    primarykey
    data
    text
    <p>Using numpy's <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.nditer.html" rel="nofollow">nditer</a>, is it possible to manually handle dimensions with different lengths?</p> <p>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)?</p> <p>Another way to ask this would be, is it possible to ask nditer to allow me to manually iterate over a set of dimensions I provide?</p> <p>I want to be able to do something like this (modified from this <a href="http://docs.scipy.org/doc/numpy/reference/arrays.nditer.html#putting-the-inner-loop-in-cython" rel="nofollow">example</a>)</p> <pre><code>@cython.boundscheck(False) def sum_squares_cy(arr): 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] = -1 out = zeros((arr.shape[0], 10)) it = np.nditer([arr, out], flags=['reduce_ok', 'external_loop', 'buffered', 'delay_bufalloc'], op_flags=[['readonly'], ['readwrite', 'no_broadcast']], op_axes=[None, axeslist], op_dtypes=['float64', 'float64']) it.operands[1][...] = 0 it.reset() for xarr, yarr in it: x = xarr y = yarr size = x.shape[0] j = 0 for i in range(size): #some magic here involving indexing into x[i] and y[j] return it.operands[1] </code></pre> <p>Does this make sense? Is it possible to do?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload