numpy summation without for loop code example

numpy summation without for loop

1

1 Example

0
# To make it easier to write for me, I am going to call you matrix "A": a, and "B": b

a_sum = np.sum(a, axis=0)
a_sum = a_sum[np.newaxis]
a_sum = np.repeat(a_sum, len(b), axis=0)

b = a_sum

a_cumsum = np.cumsum(a, axis=0)
b -= a_cumsum

Other Code Examples