Skip to content
Rami Awar edited this page Mar 21, 2021 · 2 revisions

Grid basic usage

# Defining a grid, initializes to zero
grid = Grid(width=10, height=10)

# Setting grid value
grid[0, 0] = 1

# Getting grid value
print(grid[0, 0])  # >>> 1

# CANNOT use normal indexing
print(grid[0][0])  # >>> IndexError!

# Slicing grid
subgrid = grid[1:3, 1:3]  # Returns another Grid instance, but with the same references

row = grid[0, :] # Returns Grid of height = 1, width = 10
column = grid[:, 1] # Returns Grid of height = 10, width = 1

Clone this wiki locally