Home > Blockchain >  Paths in Python/Sage
Paths in Python/Sage

Time:10-06

How to plot paths in Python/Sage?

CodePudding user response:

You can get all the paths with a nested for loop (or list comprehension).

So this will give all the paths.

def NE_lattice_paths(x,y):

    paths = []
    for i in range(x):
        path = []
        for j in range(y):
            path.append((i,j))
        paths.append(path)


    return paths

result = NE_lattice_paths(5,3)
print(result)

result

[[(0, 0), (0, 1), (0, 2)], [(1, 0), (1, 1), (1, 2)], [(2, 0), (2, 1), (2, 2)], [(3, 0), (3, 1), (3, 2)], [(4, 0), (4, 1), (4, 2)]]

I will leave it as an excersize for the OP to do the animation...

  • Related