> How about this hackish solution, for a quick non-looping fix? > > In [39]: a = np.array([1,2,3,4,np.nan,1,2,3,np.nan,3]) > idx = np.flatnonzero(np.isnan(a)) > a_ = a.copy() > a_[idx] = 0 > np.add.reduceat(a_, np.hstack((0,idx))) > Out[39]: array([ 10., 6., 3.]) >
Close, but not exactly what I need. I want the 'cumsum', so given the 'a' in your example: array([1,2,6,10,0,1,3,6,0,3]) I just made a loop, testing for 'nan'. Not elegant, but it works so I am not complaining. Kindest regards, Tim
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion