Numerical Python Tom LeFebvre. Sept. 24-27, 2002Numerical Python2 Since Python is an interpreted language, we need better performance particularly when.

Slides:



Advertisements
Similar presentations
Solving Equations A Solution
Advertisements

Decision Making EE2372 Software Design I Dr. Gerardo Rosiles.
Chapter 41 Variables and JSP Control Structures JavaServer Pages By Xue Bai.
1 Conditional Statement. 2 Conditional Statements Allow different sets of instructions to be executed depending on truth or falsity of a logical condition.
Arrays, A1 COMP 401, Fall 2014 Lecture 4 8/28/2014.
ECS 15 if and random. Topic  Testing user input using if statements  Truth and falsehood in Python  Getting random numbers.
Week 6 - Programming I So far, we’ve looked at simple programming via “scripts” = programs of sequentially evaluated commands Today, extend features to:
Programming Logic and Design Sixth Edition
Do/Loops A loop repeats a series of instructions. An iteration is a single execution of the statement(s) in the loop. Used when the exact number of iterations.
Week 5 while loops; logic; random numbers; tuples Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except.
 Introduction  Algorithm  Framework  Future work  Demo.
Week 6 - Programming I So far, we’ve looked at simple programming via “scripts” = programs of sequentially evaluated commands Today, extend features to:
Week 7 - Programming I Relational Operators A > B Logical Operators A | B For Loops for n = 1:10 –commands end.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Logical and Relational Expressions Nested if statements.
Searching and Sorting Arrays
CS 106 Introduction to Computer Science I 02 / 19 / 2007 Instructor: Michael Eckmann.
An Introduction to C Programming Geb Thomas. Learning Objectives Learn how to write and compile a C program Learn what C libraries are Understand the.
CMPT 120 Lists and Strings Summer 2012 Instructor: Hassan Khosravi.
Chapter 9 IF Statement Bernard Chen. If Statement The main statement used for selecting from alternative actions based on test results It’s the primary.
PHP H ypertext P re-processor. Unit 6 - PHP - Hello World! - Data types - Control structures - Operators.
Unit 5 while loops; logic; random numbers; tuples Special thanks to Roy McElmurry, John Kurkowski, Scott Shawcroft, Ryan Tucker, Paul Beck for their work.
The Scientific Method A Way to Solve a Problem
CIS Computer Programming Logic
Introduction to Python Basics of the Language. Install Python Find the most recent distribution for your computer at:
Branching and Conditions CSIS 1595: Fundamentals of Programming and Problem Solving 1.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
Chapter 3: Data Types and Operators JavaScript - Introductory.
Introduction to Python By Neil Cook Twitter: njcuk Slides/Notes:
CSI 3125, Axiomatic Semantics, page 1 Axiomatic semantics The assignment statement Statement composition The "if-then-else" statement The "while" statement.
Oct 15, 2007Sprenkle - CS1111 Objectives Creating your own functions.
Lecture 8. MIPS Instructions #3 – Branch Instructions #1 Prof. Taeweon Suh Computer Science Education Korea University 2010 R&E Computer System Education.
Logic (continuation) Boolean Logic and Bit Operations.
Introduction to Java Java Translation Program Structure
Data Collections: Lists CSC 161: The Art of Programming Prof. Henry Kautz 11/2/2009.
Introduction to Matlab Module #4 Page 1 Introduction to Matlab Module #4 – Programming Topics 1.Programming Basics (fprintf, standard input) 2.Relational.
Python Mini-Course University of Oklahoma Department of Psychology Lesson 21 NumPy 6/11/09 Python Mini-Course: Lesson 21 1.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 8 Arrays.
More about Strings. String Formatting  So far we have used comma separators to print messages  This is fine until our messages become quite complex:
CS105 Computer Programming PYTHON (based on CS 11 Python track: lecture 1, CALTECH)
Digital Image Processing Lecture 6: Introduction to M- function Programming.
Beginning Fortran Introduction 13 October 2009 *Black text on white background provided for easy printing.
Fundamental Programming Fundamental Programming More on Repetition.
A Level Computing#BristolMet Session Objectives#U2 S3 MUST use/read programme flow charts accurately SHOULD adapt the calculator programme to include a.
Lecturer: Nguyen Thi Hien Software Engineering Department Home page: hienngong.wordpress.com Chapter 2: Language C++
Conditional statements and boolean expressions Arithmetic, relational and logical operators.
Modules. Modules Modules are the highest level program organization unit, usually correspond to source files and serve as libraries of tools. Each file.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
 Array ◦ Single & Multi-dimensional  Java Operators ◦ Assignment ◦ Arithmetic ◦ Relational ◦ Logical ◦ Bitwise & other.
PYTHON FOR HIGH PERFORMANCE COMPUTING. OUTLINE  Compiling for performance  Native ways for performance  Generator  Examples.
Euphoria Programming Language CSC 507 Kasilingam Vimalan.
PH2150 Scientific Computing Skills Control Structures in Python In general, statements are executed sequentially, top to bottom. There are many instances.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
Numerical Python Tom LeFebvre.
Bool operators and, or, not
Introduction to Python
PH2150 Scientific Computing Skills
JavaScript Selection Statement Creating Array
CSE Social Media & Text Analytics
Introduction to Python
CMSC 120: Visualizing Information 3/25/08
Axiomatic semantics Points to discuss: The assignment statement
Python: Array Slicing Damian Gordon.
Control Structures: for & while Loops
What does this do? def revList(L): if len(L) < = 1: return L x = L[0] LR = revList(L[1:]) return LR + x.
Three Special Structures – Case, Do While, and Do Until
For Loops (Iteration 1) Programming Guides.
Introduction to Python
The return Statement © 2018 Kris Jordan.
Introduction to Computer Science
Control 9 / 25 / 19.
Presentation transcript:

Numerical Python Tom LeFebvre

Sept , 2002Numerical Python2 Since Python is an interpreted language, we need better performance particularly when crunching numbers. Advantages: High-level language allows very fast development Disadvantages: Not always intuitive

Sept , 2002Numerical Python3 Numerical Python operates on “multiarrays” One line of Numerical Python processes one or more whole arrays, not just one number. Currently NumPy is implemented as an “extension” to Python. But soon it will be an intrinsic part of Python

Sept , 2002Numerical Python4 Importing Numeric You must import the Numeric module before using Numerical Python  import Numeric  or  >>> from Numeric import *

Sept , 2002Numerical Python5 Making Numeric Arrays >>> a = array ([0, 1, -2, 6, -5]) >>> a >>> b = arrayrange(10) >>> b

Sept , 2002Numerical Python6 Multi-dimensional Arrays >>> a = array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) >>> a = array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) >>> a >>> a >>> a.shape

Sept , 2002Numerical Python7 Creating Special Arrays >>> BunchaOnes = ones((4, 4)) >>> BunchaOnes >>> BunchaZeros = zeros((4, 4)) >>> BunchaZeros

Sept , 2002Numerical Python8 Manipulating Arrays >>> BunchaThrees = BunchaOnes * 3 >>> BunchaThrees >>> f = arrayrange(0, 100, 5) >>> c = (f - 32) * 5 / 9 >>> c >>> c = (f - 32) * 5 / 9.0 >>> c

Sept , 2002Numerical Python9 Array Slicing Slicing Operator “[:]”Slicing Operator “[:]” array[start : stop : increment] array[start : stop : increment] array - a Numeric Python array start - begin here including this index stop - end here but do not include this index increment - skip this many

Sept , 2002Numerical Python10 Slicing Arrays >>> a = arrayrange(10) >>> a >>> a[2] >>> a[0:4] >>> a[-1] >>> a[:-1] >>> a[2] = -999 >>> a

Sept , 2002Numerical Python11 Slicing Multi-dimensional Arrays >>> b = reshape(arrayrange(9), (3, 3)) >>> b >>> b[0, 0] >>> b [2, 1] >>> b[-1, -1]

Sept , 2002Numerical Python12 Slicing Multi-dimensional Arrays >>> b >>> b[0:1, 0] >>> b[0:2, 0:2] >>> b [:] >>> b[::2] >>> b[::-1] >>> b[::-1, ::-1]

Sept , 2002Numerical Python13 Some Useful Functions >>> a = arrayrange(10) >>> a >>> add.reduce(a)

Sept , 2002Numerical Python14 Logical Functions - makes 0 s or 1 s >>> b = reshape(arrayrange(25), (5, 5)) >>> b >>> less (b, 12) >>> greater(b, 7) >>> less_equal(b, 10)

Sept , 2002Numerical Python15 Array Functions - where() where(condition, true value, false value) >>> b >>> c = where (less(b, 12), 0, b) >>> c Note: 0 is false, everything else is true “where” is the Numerical Python “if” statement

Sept , 2002Numerical Python16 Array Functions - clip() clip(array, min, max) >>> b >>> d = clip(b, 5, 15) >>> d