Consider the following snippet of code:
n_samples, n_rows, n_cols, n_boxes_per_cell, _ = Y_pred.shape
for example in range(n_samples):
for x_grid in range(n_rows):
for y_grid in range(n_cols):
for bnd_box in range(n_boxes_per_cell):
bnd_box_label = Y_pred[example, x_grid, y_grid, bnd_box]
do_some_stuff(bnd_box_label, x_grid, y_grid)
How can I get functionally equivalent code with at most one explicit iteration? Notice that I need the indices x_grid and y_grid.