Python Review.

Slides:



Advertisements
Similar presentations
CATHERINE AND ANNIE Python: Part 3. Intro to Loops Do you remember in Alice when you could use a loop to make a character perform an action multiple times?
Advertisements

Maths for Computer Graphics
CIS 101: Computer Programming and Problem Solving Lecture 2 Usman Roshan Department of Computer Science NJIT.
Matrix Definition A Matrix is an ordered set of numbers, variables or parameters. An example of a matrix can be represented by: The matrix is an ordered.
Matrices The Basics Vocabulary and basic concepts.
Arithmetic Operations on Matrices. 1. Definition of Matrix 2. Column, Row and Square Matrix 3. Addition and Subtraction of Matrices 4. Multiplying Row.
Computation for Physics 計算物理概論
Handling Lists F. Duveau 16/12/11 Chapter 9.2. Objectives of the session: Tools: Everything will be done with the Python interpreter in the Terminal Learning.
Announcements Additional office hours tomorrow: 3-6pm in HAAS 142 Midterm Bring a #2 pencil (test given via scantron sheet) Photo ID No Labs or Recitation.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 8 Working.
ENG College of Engineering Engineering Education Innovation Center 1 Array Accessing and Strings in MATLAB Topics Covered: 1.Array addressing. 2.
1 CS 177 Week 2 Recitation Slides Introduction. 2 Announcements.
Computation for Physics 計算物理概論 Introduction to NumPy and SciPy.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 3: Built-in functions.
(4-2) Adding and Subtracting Matrices Objectives: To Add and subtract Matrices To solve certain Matrix equations.
Magic 8 ball. "Design and write a python program that emulates a Magic Eight Ball. Your program should continually prompt the user to enter a question.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
Lists/Dictionaries. What we are covering Data structure basics Lists Dictionaries Json.
Data Structures So far, we have seen native data structures: Simple values: int, float, Boolean Sequences: Range, string, list Tuple, dictionary (chapter.
Introduction to python programming
Introduction to python
String and Lists Dr. José M. Reyes Álamo.
PH2150 Scientific Computing Skills
COMPSCI 107 Computer Science Fundamentals
Social Computing and Big Data Analytics 社群運算與大數據分析
Linear Algebra review (optional)
IGCSE 4 Cambridge Data types and arrays Computer Science Section 2
Numpy (Numerical Python)
Copyright © 2009 Dan Nettleton
Module 5 Working with Data
Intro To Pete Alonzi University of Virginia Library
Matrix 2015/11/18 Hongfei Yan zip(*a) is matrix transposition
Regression.
Introduction to Programming for Mechanical Engineers (ME 319)
Matrix Operations SpringSemester 2017.
Introduction to Python programming
CSE Social Media & Text Analytics
Numerical Computing in Python
Lists in Python.
Balance Scale Data Set This data set was generated to model psychological experimental results. Each example is classified as having the balance scale.
PH2150 Scientific Computing Skills
Matlab tutorial course
Data Structures – 1D Lists
4. sequence data type Rocky K. C. Chang 16 September 2018
CSCI N207 Data Analysis Using Spreadsheet
Numpy (Numerical Python)
String and Lists Dr. José M. Reyes Álamo.
2.2 Introduction to Matrices
Presented by Mirza Elahi 10/29/2018
Datatypes in Python (Part II)
Python-NumPy Tutorial
PYTHON Prof. Muhammad Saeed.
CSCI N317 Computation for Scientific Applications Unit R
Multidimensional array
Python Basics Wen-Yen Hsu, Hsiao-Lung Chan Dept Electrical Engineering
Functions continued.
Dr. Sampath Jayarathna Cal Poly Pomona
CS150 Introduction to Computer Science 1
Introduction to Computer Science
Linear Algebra review (optional)
Dr. Sampath Jayarathna Old Dominion University
Introduction to Computer Science
Python Functions.
What is the dimension of the matrix below?
Matrix Operations SpringSemester 2017.
For loop Using lists.
Python Debugging Session
EE 194/BIO 196: Modeling,simulating and optimizing biological systems
Python Open source Many applications Python 3 jupyter notebook
Introduction to Computer Science
Presentation transcript:

Python Review

Table of content Pycharm Variables Lists Read from file

Pycharm

Variables print('Hello World’) Hello = ‘Hello World’ x=3 y = 5 z = x + y print(z)

Lists #Empty string empty = [] empty = list() zero = [0] * 9 print('Zero:',zero) empty.append(3) print('Emtpy:',empty) print('Length of empty:',len(empty))

List Indexing list_range = range(8) another_list = [6,0,2,4,10,8,3] print('list_range:',list_range) print('another_list:', another_list) print('Index 5 of list_range:', list_range[5]) print(another_list[3:6])

Reading from a file

Reading from a file

Reading from a file

Reading from a file Create text file , data.txt Philadelphia New York Boston Washington DC Baltimore Seattle

Reading from a file #Read from a file data=[] with open('data.txt') as myfile: for line in myfile: data.append(line) print('data:',data)

Reading from file #Remove end of line character data=[] with open('data.txt') as myfile: for line in myfile: data.append(line.rstrip()) print('data',data)

Matrixes and Vectors: Numpy A scientific computing package for Python 𝐌= 1 2 3 4 5 6 7 8 9 𝐯= 1 2 3 import numpy M = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) v = np.array([[1],[2],[3]])

Matrixes and Vectors: Numpy print(M.shape) (3, 3) print(v.shape) (3, 1) print(v+v) [[2] [4] [6]]

Other ways of creating Matrices and Vectors a = np.zeros((2,2)) #Create an array of all zeros print(a) [[ 0. 0.] [ 0. 0.]] [[ 1. 1.]] b = np.ones((1,2)) #Create an array of all ones print(b)

c = np.full((2,2), 7) #Create a constant array print( c ) [[ 7. 7.] [ 7. 7.]] d = np.eye(2) #Create a 2x2 identity matrix print(d) [[ 1. 0.] [ 0. 1.]]

e = np.random.random((2,2)) #Create an array with random values print(e) [[ 0.96285848 0.34266397] [ 0.89280528 0.58975698]]

Element-wise Multiplication 𝐌= 1 2 3 4 5 6 7 8 9 𝐯= 1 2 3 print(np.multiply(M,v)) [[ 1 2 3] [ 8 10 12] [21 24 27]] print(np.multiply(v,v)) [[1] [4] [9]]

Transpose print(M) [[1 2 3] [4 5 6] [7 8 9]] print(M.T) [[1 4 7] [2 5 8] [3 6 9]]

print(v) [[1] [2] [3]] print(v.T) [[1 2 3]]

Stochastic Gradient Descent from sklearn.linear_model import SGDClassifier X = [[0., 0.], [1., 1.]] y = [0, 1] clf = SGDClassifier(loss="hinge", penalty="l2") clf.fit(X, y) Predict new values clf.predict([[2., 2.]]

End

Dictionaries #Empty dictionary empty_dict=dict() another_empty_dict = {} #Adding values to the dictionary non_empty_dict = {1:'CIS', 2:'419/519'} #printing values of the dictionary print('empty_dict:',empty_dict) print('non_empty_dict:', non_empty_dict[1] + non_empty_dict[2])

Dictionaries (continued) print('non_empty_dict:', non_empty_dict.keys()) print('non_empty_dict:', non_empty_dict.values()) #Adding a value to an existing dictionary non_empty_dict[3] = 'Recitation'

Dictionaries (continued) #Print dictionary print('non_empty_dict:', non_empty_dict) #Deleting from a dictionary del non_empty_dict[3] print('non_empty_dict:',non_empty_dict)