始める無料で始める

第4の次元

小さな配列(たとえば sudoku_game_and_solution)であれば、配列を表示して出力を確認するのは有効です。しかし、配列が大きくなったり高次元になると現実的ではありません。そこで重要なのが、配列の .shape を確認することです。

これから、2つの数独の問題とその解答を含む4次元配列を作成します。numpynp として読み込まれています。前の例で作成した3次元配列 game_and_solution に加えて、new_sudoku_gamenew_sudoku_solution も利用できます。

この演習はコースの一部です

NumPy入門

コースを見る

演習の手順

  • 別の2次元の問題と2次元の解答の組(new_sudoku_gamenew_sudoku_solution)から、new_game_and_solution という3次元配列を作成します。new_sudoku_gamenew_sudoku_solution の前に来るようにします。
  • 2つの3次元配列 game_and_solutionnew_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(____)
コードを編集して実行