# -*- coding: utf-8 -*- """ Created on Sat Sep 20 15:39:27 2020# @author: Jake Bobowski """ # Created using Spyder(Python 3.7) # Lists # Lists are created using square brackets. import math xData = [1, 2, 5, 12, -3, 3.4, math.pi, 19, -12] print(xData) # You can use 'len' to check the number of elements in a list. print(len(xData)) # Here's another list of the same length. yData = [2, 3, 4, 5, 5, 4, 3, 2, 4] print(len(yData)) # You can also automatically generate a list. x = list(range(11, 22)) print(x) # Using a third option in range, you can specify the increment of the list. x = list(range(11, 22, 2)) print(x) y = list(range(22, 11,-1)) print(y) # It is possible select specific elements of a list using square brackets. # Note that the first element is indexed as zero and the nth element is indexed # as n-1. print(xData[0]) print(xData[len(xData) - 1]) # You can also extract a range of values from the list. print(xData[1:6]) # To facilate algebraic operations on lists, it is most convenient to use the # 'NumPy' module and convery the lists to arrays. import numpy as np xArray = np.array(xData) print(xArray) # Now you can scale the array... print(2*xArray) # square each element in the array... print(xArray**2) # do element by element addition and products... yArray = np.array(yData) print(xArray - yArray) print(xArray*yArray) # evaluate dot products... print(np.dot(xArray, yArray)) # and evaluate cross products of 3-elemnet arrays (among other things) x3 = np.array([1, 2, 3]) y3 = np.array([6, 5, 4]) print(np.cross(x3, y3))