SUM only of positive numbers from array

Davorin Bajic davorinbajic at gmail.com
Fri Jan 8 07:33:15 EST 2016


On Friday, January 8, 2016 at 5:13:06 AM UTC+1, Davorin Bajic wrote:
> Hi All,
> 
> I should help...
> 
> I want to calculate the sum of a positive number, for each row:
> 
> 
> x = ((mat_1 / s_1T)-(s_2 / total))
> y = (np.sum(x > 0, axis=1)).reshape(-1, 1).tolist()
> 
> However, this part of the code only calculation count, I need sum.
> 
> Any ideas how to solve this problem?
> 
> thanks in advance

Tnx Peter,

I solved using mask and filled

x = ((mat_1 / s_1T)-(s_2 / total))
i_bolean = x < 0 
amasked = np.ma.array(x, mask=i_bolean) 
fill_value = 0. 
aunmasked = np.ma.filled(amasked, fill_value) 
y = (aunmasked.sum(axis=1)).reshape(-1, 1).tolist()



More information about the Python-list mailing list