mxnet.np.bincount¶
-
bincount
(x, weights=None, minlength=0)¶ Count number of occurrences of each value in array of non-negative ints.
- Parameters
x (ndarray) – input array, 1 dimension, nonnegative ints.
weights (ndarray) – input weigths same shape as x. (Optional)
minlength (int) – A minimum number of bins for the output. (Optional)
- Returns
out – the result of binning the input array. The length of out is equal to amax(x)+1.
- Return type
ndarray
- Raises
Value Error – 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.
Examples
>>> np.bincount(np.arange(5)) array([1, 1, 1, 1, 1]) >>> np.bincount(np.array([0, 1, 1, 3, 2, 1, 7])) array([1, 3, 1, 1, 0, 0, 0, 1])
>>> x = np.array([0, 1, 1, 3, 2, 1, 7, 23]) >>> np.bincount(x).size == np.amax(x)+1 True
>>> np.bincount(np.arange(5, dtype=float)) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: array cannot be safely cast to required type
>>> w = np.array([0.3, 0.5, 0.2, 0.7, 1., -0.6]) # weights >>> x = np.array([0, 1, 1, 2, 2, 2]) >>> np.bincount(x, weights=w) array([ 0.3, 0.7, 1.1])
Did this page help you?
Yes
No
Thanks for your feedback!