From b034f6dc33ebfef2e389a7b011c7b7920cc44f68 Mon Sep 17 00:00:00 2001 From: Sanjana M Moodbagil Date: Fri, 16 Sep 2022 19:25:10 +0000 Subject: Added example to np.prod --- numpy/core/fromnumeric.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'numpy/core/fromnumeric.py') diff --git a/numpy/core/fromnumeric.py b/numpy/core/fromnumeric.py index e1c99e61f..fda4d71e0 100644 --- a/numpy/core/fromnumeric.py +++ b/numpy/core/fromnumeric.py @@ -3044,6 +3044,9 @@ def prod(a, axis=None, dtype=None, out=None, keepdims=np._NoValue, >>> np.prod([[1.,2.],[3.,4.]], axis=1) array([ 2., 12.]) + >>> np.prod([[1.,2.,3.],[3.,4.,5.],[1.,3.,5.]], axis=0) + array([ 3., 24., 75.]) + Or select specific elements to include: >>> np.prod([1., np.nan, 3.], where=[True, False, True]) -- cgit v1.2.1 From f32c3e61d34235e4bc8833cbc364ac7451b4074e Mon Sep 17 00:00:00 2001 From: Ross Barnowski Date: Tue, 27 Sep 2022 14:27:23 -0700 Subject: DOC: Apply Chuck's suggestion. Co-authored-by: Charles Harris --- numpy/core/fromnumeric.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'numpy/core/fromnumeric.py') diff --git a/numpy/core/fromnumeric.py b/numpy/core/fromnumeric.py index fda4d71e0..6e463f409 100644 --- a/numpy/core/fromnumeric.py +++ b/numpy/core/fromnumeric.py @@ -3036,16 +3036,16 @@ def prod(a, axis=None, dtype=None, out=None, keepdims=np._NoValue, Even when the input array is two-dimensional: - >>> np.prod([[1.,2.],[3.,4.]]) + >>> a = np.array([[1., 2.], [3., 4.]]) + >>> np.prod(a) 24.0 But we can also specify the axis over which to multiply: - >>> np.prod([[1.,2.],[3.,4.]], axis=1) + >>> np.prod(a, axis=1) array([ 2., 12.]) - - >>> np.prod([[1.,2.,3.],[3.,4.,5.],[1.,3.,5.]], axis=0) - array([ 3., 24., 75.]) + >>> np.prod(a, axis=0) + array([3., 8.]) Or select specific elements to include: -- cgit v1.2.1