I do not see any condition?
If i correctly understand what you're writting (index means row), then the following snippet works.
Of course you can replace "Matrix" by the corresponding " A", "B" and "C"
If i correctly understand what you're writting (index means row), then the following snippet works.
Of course you can replace "Matrix" by the corresponding " A", "B" and "C"
import numpy as np import time Nmax = 10_000 r, c = 1_000_000, 3 Matrix = np.arange(r*c).reshape(r, c) # for all the matrix except the first row t0=time.time() D = np.zeros((r, 1)) i = np.arange(1, r) D[i, 0] = Matrix[i-1, 2] - Matrix[i, 0] + Matrix[i, 1] # only for the first row i = 0 D[i, 0] = Matrix[i, 2] + Matrix[i, 0] - Matrix[i, 1] D = D.astype(int) t1 = time.time() print(f"Duration = {t1-t0}") print(f"D = {D}")
Output:D = [[ 1]
[ 3]
[ 6]
...
[2999991]
[2999994]
[2999997]]