Вот еще одна строка:
A = np.random.randint(0,10,(6,4))
A
# array([[0, 8, 7, 6],
# [3, 2, 0, 4],
# [5, 6, 6, 4],
# [4, 5, 0, 3],
# [7, 9, 6, 8],
# [0, 9, 8, 3]])
cap = 15
np.diff(np.minimum(A.cumsum(0),cap),axis=0,prepend=0)
# array([[0, 8, 7, 6],
# [3, 2, 0, 4],
# [5, 5, 6, 4],
# [4, 0, 0, 1],
# [3, 0, 2, 0],
# [0, 0, 0, 0]])
Или в две строки, избегая медленных prepend
:
out = np.minimum(A.cumsum(0),cap)
out[1:] -= out[:-1]
out
# array([[0, 8, 7, 6],
# [3, 2, 0, 4],
# [5, 5, 6, 4],
# [4, 0, 0, 1],
# [3, 0, 2, 0],
# [0, 0, 0, 0]])