@@ -889,16 +889,17 @@ def vdot(a, b):
889
889
890
890
891
891
@array_function_from_c_func_and_dispatcher (_multiarray_umath .bincount )
892
- def bincount (x , weights = None , minlength = None ):
892
+ def bincount (x , weights = None , minlength = None , initial = None , out = None ):
893
893
"""
894
- bincount(x, /, weights=None, minlength=0)
894
+ bincount(x, /, weights=None, minlength=0, initial=None, out=None )
895
895
896
896
Count number of occurrences of each value in array of non-negative ints.
897
897
898
898
The number of bins (of size 1) is one larger than the largest value in
899
899
`x`. If `minlength` is specified, there will be at least this number
900
900
of bins in the output array (though it will be longer if necessary,
901
- depending on the contents of `x`).
901
+ depending on the contents of `x`). If `out` is specified, its size must
902
+ be large enough to contain all of the bins.
902
903
Each bin gives the number of occurrences of its index value in `x`.
903
904
If `weights` is specified the input array is weighted by it, i.e. if a
904
905
value ``n`` is found at position ``i``, ``out[n] += weight[i]`` instead
@@ -912,22 +913,32 @@ def bincount(x, weights=None, minlength=None):
912
913
Weights, array of the same shape as `x`.
913
914
minlength : int, optional
914
915
A minimum number of bins for the output array.
916
+ initial: ndarray, 1 dimension, optional
917
+ Array of initial values for each bin. It must have the same shape and
918
+ buffer length as the expected output
919
+ out: ndarray, 1 dimenion, optional
920
+ Alternative output array in which to place the result. It must have the
921
+ same shape and buffer length as the expected output but the type will
922
+ be cast when safe.
915
923
916
924
.. versionadded:: 1.6.0
917
925
918
926
Returns
919
927
-------
920
928
out : ndarray of ints
921
929
The result of binning the input array.
922
- The length of `out` is equal to ``np.amax(x)+1``.
930
+ The length of `out` is equal to ``max(minlength, np.amax(x)+1) ``.
923
931
924
932
Raises
925
933
------
926
934
ValueError
927
935
If the input is not 1-dimensional, or contains elements with negative
928
- values, or if `minlength` is negative.
936
+ values, or if `minlength` is negative, or initial or out do not have
937
+ sufficient sizes, or initial and out have different sizes.
929
938
TypeError
930
- If the type of the input is float or complex.
939
+ If the type of the input is float or complex, or `minlength` cannot be
940
+ converted to int, or `initial` or `out` cannot be safely converted to
941
+ the expected type.
931
942
932
943
See Also
933
944
--------
0 commit comments