第4の次元
小さな配列(たとえば sudoku_game_and_solution)であれば、配列を表示して出力を確認するのは有効です。しかし、配列が大きくなったり高次元になると現実的ではありません。そこで重要なのが、配列の .shape を確認することです。
これから、2つの数独の問題とその解答を含む4次元配列を作成します。numpy は np として読み込まれています。前の例で作成した3次元配列 game_and_solution に加えて、new_sudoku_game と new_sudoku_solution も利用できます。
この演習はコースの一部です
NumPy入門
演習の手順
- 別の2次元の問題と2次元の解答の組(
new_sudoku_gameとnew_sudoku_solution)から、new_game_and_solutionという3次元配列を作成します。new_sudoku_gameがnew_sudoku_solutionの前に来るようにします。 - 2つの3次元配列
game_and_solutionとnew_game_and_solution(この順番)から配列を作り、games_and_solutionsという4次元配列を作成します。 games_and_solutionsの shape を出力します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# 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(____)