Directions: In this section, use Jupyter Notebook. All work should be done using python. Upload your work to HTML. Then highlight via HTML and upload to GT Canvas.
List is a built-in data type in python, but array is not. List can contains elements with different types, but elements of an array must have the same type as each other. Each of element of a list has a header and can be saved in a memory space separately, but all elements of an array will be saved in adjacent memory spaces. List needs more space and is not efficient if all the elements have the same type.
It creates two 1D arrays.
from numpy import array
x1 = array([5,6])
print(x1)
## [5 6]
x2 = array([8,9])
print(x2)
## [8 9]
The first element has index of 0 and the last one has -1 (also index 3 in this specific array).
data = array([1,3,2,6])
data[1]
## 3
data[3]
## 6
data[ -3]
## 3
data[ -4]
## 1
data[0]
## 1
using : we can slice an array from the index we specify to the element before the second index we specify. For example the first on selects the first 3 elements of the array. The second one selects the last 2 elements. The third one selects the 4th element and the last command selects the 2nd, 3rd, and 4th elements.
data = array([6,8,10,12,15])
data[0:3]
## array([ 6, 8, 10])
data[ -2: ]
## array([12, 15])
data[3:4]
## array([12])
data[1:4]
## array([ 8, 10, 12])