Aan de slagGa gratis aan de slag

The fourth dimension

Printing arrays is a good way to check code output for small arrays like sudoku_game_and_solution, but it becomes unwieldy when dealing with bigger arrays and those with higher dimensions. Another important check is to look at the array's .shape.

Now, you'll create a 4D array that contains two sudoku games and their solutions. numpy is loaded as np. The game_and_solution 3D array you created in the previous example is available, along with new_sudoku_game and new_sudoku_solution.

Deze oefening maakt deel uit van de cursus

Introduction to NumPy

Cursus bekijken

Oefeninstructies

  • Create another 3D array called new_game_and_solution with a different 2D game and 2D solution pair: new_sudoku_game and new_sudoku_solution. new_sudoku_game should appear before new_sudoku_solution.
  • Create a 4D array called games_and_solutions by making an array out of the two 3D arrays: game_and_solution and new_game_and_solution, in that order.
  • Print the shape of games_and_solutions.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Create a second 3D array of another game and its solution 
new_game_and_solution = ____

# Create a 4D array of both game and solution 3D arrays
games_and_solutions = ____

# Print the shape of your 4D array
print(____)
Code bewerken en uitvoeren