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!
Questo esercizio fa parte del corso
Introduction to NumPy
Istruzioni dell'esercizio
- Import NumPy using its generally accepted alias.
- Convert
sudoku_listinto a NumPy array calledsudoku_array. - Print the class
type()ofsudoku_arrayto check that your code has worked properly.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
# Import NumPy
import ____
# Convert sudoku_list into an array
sudoku_array = ____
# Print the type of sudoku_array
print(____)