1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Python for Finance

Connected

Exercise

Create an array

You can use the NumPy package to create arrays. NumPy arrays are optimized for numerical analyses and contain only a single data type. To convert a list to an array, you can use the array() function from NumPy.

import numpy as np

a_list = [1, 2, 3, 4]
a_list

[1, 2, 3, 4]

an_array = np.array(a_list)
an_array

array([1, 2, 3, 4])

Instructions

100 XP
  • Import numpy using the alias np.
  • Create prices_array and earnings_array arrays from the lists prices and earnings, respectively.