Skip to content

Commit c3afdda

Browse files
committed
fix: warning when using np.prod in NumPy 1.19
1 parent ea838c1 commit c3afdda

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

examples/simple_density.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import numpy as np
55
import boost_histogram as bh
66
import matplotlib.pyplot as plt
7+
import functools
8+
import operator
79

810
# Make a 2D histogram
911
hist = bh.Histogram(bh.axis.Regular(50, -3, 3), bh.axis.Regular(50, -3, 3))
@@ -12,7 +14,7 @@
1214
hist.fill(np.random.normal(size=1_000_000), np.random.normal(size=1_000_000))
1315

1416
# Compute the areas of each bin
15-
areas = np.prod(hist.axes.widths, axis=0)
17+
areas = functools.reduce(operator.mul, hist.axes.widths)
1618

1719
# Compute the density
1820
density = hist.view() / hist.sum() / areas

notebooks/BoostHistogramHandsOn.ipynb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
"source": [
1818
"import boost_histogram as bh\n",
1919
"import numpy as np\n",
20-
"import matplotlib.pyplot as plt"
20+
"import matplotlib.pyplot as plt",
21+
"import functools",
22+
"import operators"
2123
]
2224
},
2325
{
@@ -1013,7 +1015,7 @@
10131015
"hist7 = bh.numpy.histogram(data1 - 3.5, bins=bins, histogram=bh.Histogram)\n",
10141016
"\n",
10151017
"widths = hist7.axes.widths\n",
1016-
"area = np.prod(widths, axis=0)\n",
1018+
"area = functools.reduce(operator.mul, hist.axes.widths)\n",
10171019
"\n",
10181020
"area"
10191021
]

src/boost_histogram/numpy.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
from ._internal.kwargs import KWArgs as _KWArgs
1111
from ._internal.sig_tools import inject_signature as _inject_signature
12+
from functools import reduce as _reduce
13+
from operator import mul as _mul
1214

1315
import numpy as _np
1416

@@ -74,7 +76,7 @@ def histogramdd(
7476
hist = cls(*axs, storage=bh_storage).fill(*a, weight=weights, threads=threads)
7577

7678
if density:
77-
areas = np.prod(hist.axes.widths, axis=0)
79+
areas = _reduce(_mul, hist.axes.widths)
7880
density = hist.view() / hist.sum() / areas
7981
return (density,) + hist.to_numpy()[1:]
8082

0 commit comments

Comments
 (0)