Presentation is loading. Please wait.

Presentation is loading. Please wait.

Numerical Python Tom LeFebvre.

Similar presentations


Presentation on theme: "Numerical Python Tom LeFebvre."— Presentation transcript:

1 Numerical Python Tom LeFebvre

2 Numerical Python 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 , 2002 Numerical Python

3 Numerical Python 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 , 2002 Numerical Python

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

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

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

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

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

9 Array Slicing Slicing Operator “[:]” 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 , 2002 Numerical Python

10 Slicing Arrays >>> a = arrayrange(10) >>> a
Sept , 2002 Numerical Python

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

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

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

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

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

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


Download ppt "Numerical Python Tom LeFebvre."

Similar presentations


Ads by Google