Name
reduce
Synopsis
u
.reduce(a
,axis
=0)
Returns an array r
with the same type code
as a
and rank one less than
a
’s rank. Each element of
r
is the reduction of the elements of
a
, along the given
axis
, with the function or operator
underlying u
. The functionality of
u
.reduce
is therefore
close to that of Python’s built-in
reduce
function, covered in Chapter 8. For example, since
0+1+2+...+9
is 45
,
add.reduce(range(10))
is 45
.
This is just like, when using built-in reduce
and
import
operator
,
reduce(operator.add,range(10))
is also
45
.
Get Python in a Nutshell 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.