summaryrefslogtreecommitdiff
path: root/numpy/core/fromnumeric.py
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2022-09-28 08:00:12 +0200
committerGitHub <noreply@github.com>2022-09-28 08:00:12 +0200
commit4f2bf689cdadaebfdb804674630e4e9eace91cd4 (patch)
treef4ea17c80ddecbb821267e0d6def9255b67f78f1 /numpy/core/fromnumeric.py
parent9c5a2b41cc0ade160a01b7423630f7ee1b8e63dc (diff)
parentf32c3e61d34235e4bc8833cbc364ac7451b4074e (diff)
downloadnumpy-4f2bf689cdadaebfdb804674630e4e9eace91cd4.tar.gz
Merge pull request #22297 from sanjanamm98/np.prod-example-issue#22266
DOC: Add example to np.prod
Diffstat (limited to 'numpy/core/fromnumeric.py')
-rw-r--r--numpy/core/fromnumeric.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/numpy/core/fromnumeric.py b/numpy/core/fromnumeric.py
index ed1eeb908..f4c7af88a 100644
--- a/numpy/core/fromnumeric.py
+++ b/numpy/core/fromnumeric.py
@@ -3036,14 +3036,17 @@ 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(a, axis=0)
+ array([3., 8.])
+
Or select specific elements to include:
>>> np.prod([1., np.nan, 3.], where=[True, False, True])