Content-Length: 1697 | pFad | http://github.com/numpy/numpy/pull/23552.diff

thub.com diff --git a/numpy/_core/multiarray.py b/numpy/_core/multiarray.py index 8348522e8420..5624995f1822 100644 --- a/numpy/_core/multiarray.py +++ b/numpy/_core/multiarray.py @@ -953,7 +953,8 @@ def bincount(x, weights=None, minlength=None): If the input is not 1-dimensional, or contains elements with negative values, or if `minlength` is negative. TypeError - If the type of the input is float or complex. + If the type of the input is float or complex, or larger than the + native array index type (which is equivalent to `np.intp`). See Also -------- @@ -971,8 +972,8 @@ def bincount(x, weights=None, minlength=None): >>> np.bincount(x).size == np.amax(x)+1 True - The input array needs to be of integer dtype, otherwise a - TypeError is raised: + The input array needs have an integer dtype smaller or equal to the + native array index type, otherwise a TypeError is raised: >>> np.bincount(np.arange(5, dtype=float)) Traceback (most recent call last): @@ -980,6 +981,14 @@ def bincount(x, weights=None, minlength=None): TypeError: Cannot cast array data from dtype('float64') to dtype('int64') according to the rule 'safe' + This also means that the following code will not work on a 32-bit system: + + >>> import sys + >>> if sys.maxsize <= 2**32: + ... np.bincount(np.arange(5, dtype=np.int64)) + ... # TypeError: Cannot cast array data from dtype('int64') to + ... # dtype('int32') according to the rule 'safe' + A possible use of ``bincount`` is to perform sums over variable-size chunks of an array, using the ``weights`` keyword.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/numpy/numpy/pull/23552.diff

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy