1. Slice a seating grid
Write code Easy ✓ Completedseats is a 2-D array: each row is a row of seats in a hall. Write two functions:
back_row(grid)returns the last row ofgrid.first_two_columns(grid)returns the first two columns of every row, so its shape is(number_of_rows, 2).
Both must work for a grid of any size.
import numpy as np
seats = np.arange(1, 21).reshape(4, 5)
def back_row(grid):
pass
def first_two_columns(grid):
pass
print(back_row(seats))
print(first_two_columns(seats))import numpy as np
seats = np.arange(1, 21).reshape(4, 5)
def back_row(grid):
return grid[-1]
def first_two_columns(grid):
return grid[:, :2]
print(back_row(seats))
print(first_two_columns(seats))