Formatting And Summing Up Numbers With Arrays
I am trying to calculate the T_Sum value so that for the values that are greater than the Vals values in Numbers it will just add up to the Vals values for that element. For exampl
Solution 1:
The end value of np.arange
must be greater than 105, because it's not end inclusive.
Vals = np.arange(60, 106, 5)
T_Sum = (Numbers[:,None] > Vals).sum(axis=0) * Vals
Solution 2:
The arrange method is not inclusive of the stop
value, so your Vals actually ends at 100, not 105 like you seem to think ti does.
In any case, this will do what you want, just have to play with the start/stop values to get the final result you are looking for.
import numpy as np
Vals= np.arange(start=60, stop=105, step=5)
from collections import Counter
Numbers = np.array([123.6, 130 , 150, 110.3748, 111.6992976,
102.3165566, 97.81462811 , 89.50038472 , 96.48141473 , 90.49956702, 65])
output = []
for v in Vals:
c = 0for n in Numbers:
if n>v:
c+=1print(f'There are {c}, values greater than {v}')
output.append(c*v)
print(output)
Output
There are11, values greater than 60
There are10, values greater than 65
There are10, values greater than 70
There are10, values greater than 75
There are10, values greater than 80
There are10, values greater than 85
There are9, values greater than 90
There are8, values greater than 95
There are6, values greater than 100
[660, 650, 700, 750, 800, 850, 810, 760, 600]
Post a Comment for "Formatting And Summing Up Numbers With Arrays"