diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2018-04-08 14:48:24 -0700 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2018-04-08 15:01:28 -0700 |
commit | cc1107e7daa3212576b9ce990c1fd1cd24e9e047 (patch) | |
tree | 0e7b4ba46a7130ad218017f19d9eee2b4b68fbba /numpy/lib/histograms.py | |
parent | 59d78787a518881f30e81234f2d2aee408ffa67a (diff) | |
download | numpy-cc1107e7daa3212576b9ce990c1fd1cd24e9e047.tar.gz |
MAINT: Don't use np.arange just because `range` is shadowed
Creates an alias instead
Diffstat (limited to 'numpy/lib/histograms.py')
-rw-r--r-- | numpy/lib/histograms.py | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/numpy/lib/histograms.py b/numpy/lib/histograms.py index e3b45eab1..a0346f6c5 100644 --- a/numpy/lib/histograms.py +++ b/numpy/lib/histograms.py @@ -10,6 +10,10 @@ from numpy.compat.py3k import basestring __all__ = ['histogram', 'histogramdd', 'histogram_bin_edges'] +# range is a keyword argument to many functions, so save the builtin so they can +# use it. +_range = range + def _hist_bin_sqrt(x): """ @@ -693,7 +697,7 @@ def histogram(a, bins=10, range=None, normed=False, weights=None, # large arrays, it is actually faster (for example for a 10^8 array it # is 2x as fast) and it results in a memory footprint 3x lower in the # limit of large arrays. - for i in np.arange(0, len(a), BLOCK): + for i in _range(0, len(a), BLOCK): tmp_a = a[i:i+BLOCK] if weights is None: tmp_w = None @@ -741,12 +745,12 @@ def histogram(a, bins=10, range=None, normed=False, weights=None, # Compute via cumulative histogram cum_n = np.zeros(bin_edges.shape, ntype) if weights is None: - for i in np.arange(0, len(a), BLOCK): + for i in _range(0, len(a), BLOCK): sa = np.sort(a[i:i+BLOCK]) cum_n += _search_sorted_inclusive(sa, bin_edges) else: zero = np.zeros(1, dtype=ntype) - for i in np.arange(0, len(a), BLOCK): + for i in _range(0, len(a), BLOCK): tmp_a = a[i:i+BLOCK] tmp_w = weights[i:i+BLOCK] sorting_index = np.argsort(tmp_a) @@ -873,7 +877,7 @@ def histogramdd(sample, bins=10, range=None, normed=False, weights=None): raise ValueError('range argument must have one entry per dimension') # Create edge arrays - for i in np.arange(D): + for i in _range(D): if np.ndim(bins[i]) == 0: if bins[i] < 1: raise ValueError( @@ -901,13 +905,13 @@ def histogramdd(sample, bins=10, range=None, normed=False, weights=None): # Compute the bin number each sample falls into. Ncount = tuple( np.digitize(sample[:, i], edges[i]) - for i in np.arange(D) + for i in _range(D) ) # Using digitize, values that fall on an edge are put in the right bin. # For the rightmost bin, we want values equal to the right edge to be # counted in the last bin, and not as an outlier. - for i in np.arange(D): + for i in _range(D): # Rounding precision mindiff = dedges[i].min() if not np.isinf(mindiff): @@ -940,7 +944,7 @@ def histogramdd(sample, bins=10, range=None, normed=False, weights=None): # Normalize if normed is True if normed: s = hist.sum() - for i in np.arange(D): + for i in _range(D): shape = np.ones(D, int) shape[i] = nbin[i] - 2 hist = hist / dedges[i].reshape(shape) |