5  NumPy Array Basics

This notebook focuses on creating arrays, inspecting shape and dtype, and basic indexing.

import numpy as np

sensor_readings = np.array(
    [
        [12.0, 14.5, 13.2],
        [11.8, 15.1, 13.9],
        [12.4, 14.8, 14.2],
    ]
)

sensor_readings

5.1 Exercise 1

Inspect the array shape, number of dimensions, and dtype.

# TODO: Inspect the main array properties.
array_shape = sensor_readings.____
num_dimensions = sensor_readings.____
array_dtype = sensor_readings.____

print("shape:", array_shape)
print("ndim:", num_dimensions)
print("dtype:", array_dtype)

5.2 Exercise 2

Create an array of zeros with shape (2, 4).

# TODO: Create a zeros array with the requested shape.
empty_batch = np.zeros((__, __))
empty_batch

5.3 Exercise 3

Select the first row of sensor_readings.

# TODO: Use NumPy indexing to take the first row.
first_row = sensor_readings[__, :]
first_row

5.4 Exercise 4

Select the second column across all rows.

# TODO: Keep every row, but only the second column.
second_column = sensor_readings[:, __]
second_column

5.5 Exercise 5

Create the array np.arange(2, 12, 2).

# TODO: Build an evenly spaced integer sequence.
step_values = np.arange(__, __, __)
step_values