开始使用免费开始使用

第四维

对于像 sudoku_game_and_solution 这样的较小数组,打印数组是检查代码输出的好方法。但在处理更大的数组或更高维的数组时,这种方式就不太方便了。另一个重要的检查方式是查看数组的 .shape

现在,您将创建一个包含两个数独游戏及其解的 4D 数组。numpy 已以 np 导入。您在上一个示例中创建的 3D 数组 game_and_solution 已可用,同时还提供了 new_sudoku_gamenew_sudoku_solution

本练习是课程的一部分

NumPy 入门

查看课程

练习说明

  • 创建另一个名为 new_game_and_solution 的 3D 数组,包含一对不同的 2D 游戏与 2D 解:new_sudoku_gamenew_sudoku_solutionnew_sudoku_game 应该位于 new_sudoku_solution 之前。
  • 使用两个 3D 数组 game_and_solutionnew_game_and_solution(按此顺序)创建一个名为 games_and_solutions 的 4D 数组。
  • 打印 games_and_solutions 的形状。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# 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(____)
编辑并运行代码