Time for action – applying the ufunc methods to the add function
Let's call the first four methods on the add()
function:
- The universal function reduces the input array recursively along a specified axis on consecutive elements. For the
add()
function, the result of reducing is similar to calculating the sum of an array. Call thereduce()
method:a = np.arange(9) print("Reduce", np.add.reduce(a))
The reduced array should be as follows:
Reduce 36
- The
accumulate()
method also recursively goes through the input array. But, contrary to thereduce()
method, it stores the intermediate results in an array and returns that. The result, in the case of theadd()
function, is equivalent to calling thecumsum()
function. Call theaccumulate()
method on the ...
Get NumPy : Beginner's Guide - Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.