Aan de slagGa gratis aan de slag

Your first NumPy array

Once you're comfortable with NumPy, you'll find yourself converting Python lists into NumPy arrays all the time for increased speed and access to NumPy's excellent array methods.

sudoku_list is a Python list containing a sudoku game:

[[0, 0, 4, 3, 0, 0, 2, 0, 9],
 [0, 0, 5, 0, 0, 9, 0, 0, 1],
 [0, 7, 0, 0, 6, 0, 0, 4, 3],
 [0, 0, 6, 0, 0, 2, 0, 8, 7],
 [1, 9, 0, 0, 0, 7, 4, 0, 0],
 [0, 5, 0, 0, 8, 3, 0, 0, 0],
 [6, 0, 0, 0, 0, 0, 1, 0, 5],
 [0, 0, 3, 5, 0, 8, 6, 9, 0],
 [0, 4, 2, 9, 1, 0, 3, 0, 0]]

You're going to change sudoku_list into a NumPy array so you can practice with it in later lessons, for example by creating a 4D array of sudoku games along with their solutions!

Deze oefening maakt deel uit van de cursus

Introduction to NumPy

Cursus bekijken

Oefeninstructies

  • Import NumPy using its generally accepted alias.
  • Convert sudoku_list into a NumPy array called sudoku_array.
  • Print the class type() of sudoku_array to check that your code has worked properly.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Import NumPy
import ____

# Convert sudoku_list into an array
sudoku_array = ____

# Print the type of sudoku_array 
print(____)
Code bewerken en uitvoeren