Skip to content
1 hidden cell
Introduction to NumPy
Introduction to NumPy
Run the hidden code cell below to import the data used in this course.
1 hidden cell
Take Notes
Add notes about the concepts you've learned and code cells with code you want to keep.
Add your notes here
# Add your code snippets here# Import NumPy
import numpy as np
# Convert sudoku_list into an array
sudoku_array = np.array(sudoku_list)
# Print the type of sudoku_array
print(type(sudoku_array))
# Create an array of zeros which has four columns and two rows
zero_array = np.zeros((2,4))
print(zero_array)
# Create an array of random floats which has six columns and three rows
random_array = np.random.random((3,6))
print(random_array)
# Create an array of integers from one to ten
one_to_ten = np.arange(1,11)
# Create your scatterplot
plt.scatter(one_to_ten, doubling_array)
plt.show()# Create the game_and_solution 3D array
game_and_solution = np.array([sudoku_game, sudoku_solution])
# Print game_and_solution
print(game_and_solution)
# Create a second 3D array of another game and its solution
new_game_and_solution = np.array([new_sudoku_game, new_sudoku_solution])
# Create a 4D array of both game and solution 3D arrays
games_and_solutions = np.array([game_and_solution, new_game_and_solution])
# Print the shape of your 4D array
print(games_and_solutions.shape)
# Flatten sudoku_game
flattened_game = sudoku_game.flatten()
# Print the shape of flattened_game
print(flattened_game.shape)
# Flatten sudoku_game
flattened_game = sudoku_game.flatten()
# Print the shape of flattened_game
print(flattened_game.shape)
# Reshape flattened_game back to a nine by nine array
reshaped_game = flattened_game.reshape((9, 9))
# Print sudoku_game and reshaped_game
print(sudoku_game)
print(reshaped_game)# Create an array of zeros with three rows and two columns
zero_array = np.zeros((3,2))
# Print the data type of zero_array
print(zero_array.dtype)
# Create an array of zeros with three rows and two columns
zero_array = np.zeros((3, 2))
# Print the data type of zero_array
print(zero_array.dtype)
# Create a new array of int32 zeros with three rows and two columns
zero_int_array = np.zeros((3,2), dtype=np.int32)
# Print the data type of zero_int_array
print(zero_int_array.dtype)
# Print the data type of sudoku_game
print(sudoku_game.dtype)
# Change the data type of sudoku_game to int8
small_sudoku_game = sudoku_game.astype(np.int8)
# Print the data type of small_sudoku_game
print(small_sudoku_game.dtype)