summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2018-04-08 14:40:52 -0700
committerEric Wieser <wieser.eric@gmail.com>2018-04-08 15:01:28 -0700
commit59d78787a518881f30e81234f2d2aee408ffa67a (patch)
tree9f055fe88b535c089f661f5ff374fc350107e6fe /numpy/lib
parentb3a2b026652f62ae998014544547721340ffb435 (diff)
downloadnumpy-59d78787a518881f30e81234f2d2aee408ffa67a.tar.gz
MAINT: Use the minlength argument of bincount to avoid a copy into a larger array
The result is left as a float, even though it no longer needs to be, as this commit aims not to change behavior.
Diffstat (limited to 'numpy/lib')
-rw-r--r--numpy/lib/histograms.py12
1 files changed, 4 insertions, 8 deletions
diff --git a/numpy/lib/histograms.py b/numpy/lib/histograms.py
index f0796fbac..e3b45eab1 100644
--- a/numpy/lib/histograms.py
+++ b/numpy/lib/histograms.py
@@ -919,24 +919,20 @@ def histogramdd(sample, bins=10, range=None, normed=False, weights=None):
# Shift these points one bin to the left.
Ncount[i][on_edge & not_smaller_than_edge] -= 1
- # Flattened histogram matrix (1D)
- # Reshape is used so that overlarge arrays
- # will raise an error.
- hist = np.zeros(nbin, float).reshape(-1)
-
# Compute the sample indices in the flattened histogram matrix.
# This raises an error if the array is too large.
xy = np.ravel_multi_index(Ncount, nbin)
# Compute the number of repetitions in xy and assign it to the
# flattened histmat.
- flatcount = np.bincount(xy, weights)
- a = np.arange(len(flatcount))
- hist[a] = flatcount
+ hist = np.bincount(xy, weights, minlength=nbin.prod())
# Shape into a proper matrix
hist = hist.reshape(nbin)
+ # This preserves the (bad) behavior observed in gh-7845, for now.
+ hist = hist.astype(float, casting='safe')
+
# Remove outliers (indices 0 and -1 for each dimension).
core = D*(slice(1, -1),)
hist = hist[core]