One of the most common situations you will encounter when working with data is transforming a list into an array.
When operating such a transformation, it is important to consider the objects the lists contain because this will determine the dimensionality and the dtype of the resulting array.
Let's start with this first example of a list containing just integers:
In: import numpy as npIn: # Transform a list into a uni-dimensional array list_of_ints = [1,2,3] Array_1 = np.array(list_of_ints)In: Array_1Out: array([1, 2, 3])
Remember that you can access a one-dimensional array as you would with a standard Python list (the indexing starts from zero):
In: Array_1 # let's output the second valueOut: 2