I am trying to modify the T_Sum value so that for the values that are greater then the Vals values will just add up to the Vals values for that element. So since the first element of Vals is 60 and all the values within Numbers is greater than 60 it multiplies 60 by 11 Vals*len(Numbers values greater than 60). If the Vals value is 105 there are 5 elements that are greater than 60 so the result would be 525. How could I do this without a for loop?
Vals= np.arange(start=60, stop=105, step=5) Numbers = np.array([123.6, 130 , 150, 110.3748, 111.6992976, 102.3165566, 97.81462811 , 89.50038472 , 96.48141473 , 90.49956702, 65]) T_Sum = np.ma.masked_array(np.repeat(Numbers[None,:],Vals.size,0),mask=[Numbers<Vals[:,None]]).sum(-1).data Expected Output
[660, 650, 700, 750, 800, 850, 810, ,760, 600, 525] https://stackoverflow.com/questions/66466529/formatting-and-summing-up-numbers-with-arrays-numpy-python March 04, 2021 at 07:37AM
没有评论:
发表评论