I am trying to write a code where it checks for the np.cumsum() of both a and b separated into positive and negative values. so for the first row in the outputs [12, 101, 111] it combines all the values that are over 0 being [12, 12+89, 12+89+10]. The outputs for the first and second row are of the cumsum values that are over 0 and the values for the third and fourth row are the ones for the cumsum values that are below 0. How would i be able to add that functionality to the list comprehension below and get the Expected output below?
a = np.array([12, -5, -55, 89, 10, -5.5])
b = np.array([-5, -4.5, 12.4, 11, 16])
Sum_long_profits = [(row > 0).cumsum() for row in [a, b]]
Expected output:
[[12, 101, 111],
[12.4, 23.4, 39.4],
[-5, -60, -65.5],
[-4, -9.5]]