Topic · Built-in data types in python · Arrays " Matrices · Strings Functions · If statements · For loops · Functions Python Tutorial Outline Example Text type: str Numeric types: int > x = 20, float > x = 20.5 Sequence types: list > x = ["apple", "banana", "cherry"] Range > range(6) Mapping type: dict > x = {"name" : "John", "age" : 36} You can get the data type of any object by using the type() function. Numpy library can be used to generate arrays in python: >>> numpy.array([1, 2, 3]) array([1, 2, 3]) Numpy library can be used to generate matrices in python: >>> a = numpy.matrix([1, 2, 3]) >>> a matrix([1, 2], [3, 4]]) Matrix transpose: >>> b = numpy.transpose (a) Matrix operations: - Matrix product: a*b - Multiply elements of two matrices: numpy. multiply (a,b) - Size of matrix: a . shape Strings: >>> txt = 'hello' Length of string: len(txt) Conditional statements: limit = 0.75 import random a = random. random( ) if a > limit: print('value of a is greater than the limit') else: print('value of a is less than the limit') For loops: - Print all numbers from 0 to 5, and print a message when the loop has ended:
for x in range(6): print(x) else: print("Finally finished!") Plotting Functions: - Square function def sq_func(x): return x ** 2 print(sq_func(5)) >>> 25 import matplotlib.pyplot as plt - Simple plt.plot([1, 2, 3, 4]) plt. ylabel ('numbers' ) - Bar chart Bar chart showing # of students in each course Students = [24, 33, 30] Courses = ['math' , 'physics', 'chemistry'] plt. bar (Courses, Students) - Mesh grid & Stream plots X,Y = np.meshgrid(np.arange(0,1,.1), np.arange(0,1,.1)) U = X V = - Y plt.quiver(X,Y,U,V) startx=np.arange(0, 1, .1) starty=np.ones(len(startx) ) start = np. array([startx, startx]) plt. streamplot(X, Y, U, V, start_points=start. T) - Color contour plots (contourf) X = np.arange(-2*np.pi, 2*np.pi, 0.1) y = np.arange(0, 4*np.pi, 0.1) X, Y = np.meshgrid(x,y) Z = np.sin(X) + np. cos(Y) plt.contourf(X, Y, Z, 10) Session 2: - Ex 1: Calculate tangent plane to surface https://www.youtube.com/watch?v=sGRsFxl3zOs&ab_channel=Pytho nforEconometrics - Ex 2: Differential equations https://apmonitor.com/pdc/index.php/Main/SolveDifferentialEquations