Skip to content
1 hidden cell
Introduction to Python
Introduction to Python
Run the hidden code cell below to import the data used in this course.
1 hidden cell
Numpy arrays
import numpy as np
mylist=[True, 1, "2"]
print(mylist)
print(np.array(mylist)) #all data types converted to text arrays dont support mixing of data types!!!
list1=[1,2,3]
list2=[4,5,6]
list3=list1+list2 #concatenation for regular lists
print(list3)
import numpy as np
nplist1=np.array(list1)
nplist2=np.array(list2)
list3=nplist1+nplist2 #mathematical operation on numpy arrays
print(list3)
Filtering numpy arrays
import numpy as np
nparray=np.array([1,2,3,4,5,6,7,8,9,10])
filterarray=nparray>5 #the filter used as index list must be integer or boolean
print(filterarray) #boolean
print(nparray[filterarray]) #only True values are selected
Selective import
import math as m #import entire library/package
from math import pi # import only specific part from the package (selective import)
from scipy.linalg import inv as my_inv #from package scipy and subpackage linalg import function inv with alias my_inv
Referencing lists
startinglist=[1,2,3,4,5]