Numpy Arrays: Exercises


1. Creating and Accessing NumPy Arrays. In Python, NumPy is a library that provides support for arrays and matrices. You can create a NumPy array by importing the NumPy library and using the numpy.array() function.

For example, you can create a NumPy array of numbers like this: import numpy as np; numbers = np.array([1, 2, 3, 4, 5]). To access items in a NumPy array, you can use indexing, starting with 0 for the first item.


# Import the NumPy library import numpy as np # Create a NumPy array of numbers numbers = np.array(___) # Access the second item in the array second_number = ___ # Print the second number print(second_number) # Import the NumPy library import numpy as np # Create a NumPy array of numbers numbers = np.array([1, 2, 3, 4, 5]) # Access the second item in the array second_number = numbers[1] # Print the second number print(second_number) test_object("numbers") success_msg("You have created a NumPy array of numbers and accessed the second item.")
To create a NumPy array, import NumPy and use numpy.array(). To access items, use indexing starting from 0.

Previous Exercise Next Exercise