numpy.bincount(x, weights=None, minlength=0)
Return int ndarray .
x | Input array of non negative of 1 D |
weight | (optional ), array of same size of input array. Weight of the elements to be used |
minlength | Int (optional ), minimum length of bins |
import numpy as np
ma=np.array([0,2,2,6,5])
print(np.bincount(ma))
Output
[1 0 2 0 0 1 1]
If the input array has the highest value of 6, then our output array will have 7 elements. Each element of our output array will show frequency of occurrence of numbers starting from 0 to highest number.
import numpy as np
my_array1 = np.array([0,2,2,6,5])
my_array2 = np.array([2,2,1,3,4])
my_bin=np.bincount(my_array2,weights=my_array1)
print(my_bin)
Output
[0. 2. 2. 6. 5.]
import numpy as np
my_array1 = np.array([0,2,2,6,5])
my_array2 = np.array([2,2,1,3,4])
my_bin=np.bincount(my_array1,my_array2)
print(my_bin)
Output
[2. 0. 3. 0. 0. 4. 3.]
import numpy as np
my_array1 = np.array([0,3,3,5])
my_array2 = np.array([2,1,4,6])
my_bin=np.bincount(my_array1,my_array2)
print(my_bin)
Output
[2. 0. 0. 5. 0. 6.]
Numpyones()
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.