Working With 2 Arrays With Different Lengths Numpy Python
Is there a way I could modify the function down below so that it could compute arrays with different length sizes. the length of Numbers array is 7 and the length of the Formating
Solution 1:
Here's an approach with bincounts
. Note that you have your x
and l
messed-up, and I recalled that you could/should use digitize
:
# Formating goes here
x = np.sort(Formating);
# digitize
l = np.digitize(Numbers, x)
# output:
np.bincount(l, weights=Numbers)
Out:
array([ 0., 0., 7., 30., 0., 20.])
Post a Comment for "Working With 2 Arrays With Different Lengths Numpy Python"