I have this :
def steps(ns):
return [random.choice([[0, 1], [1, 0], [0, -1], [-1, 0]]) for i in range(ns)]
which returns for example for ns=4 : [[-1, 0], [0, -1], [1, 0], [1, 0]]
I want do sth like this :
def Walk(ns):
return sc.cumsum(steps2d(ns))
in order to compute the cumsum from the above.I want for example to have :
Walk(10) : [[0, 1], [1, 1], [1, 2], [1, 3], [1, 2], [2, 2], [1, 2], [1, 3], [1,
4], [0, 4]]
With the Walk function of mine i am taking sth like :
[1 1 1 2 2 3 3 2 2 3 4 4 3 3 4 4 4 3 3 4]
Is there a way to do it?
Thanks!
Try
scipy.cumsum(..., axis=0).