Reduce

For each one-dimensional sequence along the axis dimension of the array, return a single number resulting from recursively applying the operation to succesive elements along that dimension. If the input array has N dimensions, then the returned array has N — 1 dimensions. This produces the equivalent of the following Python code :

>>> indx = [index_exp [: ] ] *array.ndim >>> indx[axis] = 0; N=array.shape[axis] >>> result = array[indx].astype(dtype) >>> for i in range(1,N): ... indx[axis] = i

Studying the above code can also help you gain an appreciation for how to do generic indexing in Python using index_exp. For example, if <op> is add, then <op>.reduce produces a summation along the given axis. If <op> is prod, then a repeated multiply is performed.

0 0

Post a comment