Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Numerical Python Tom LeFebvre. Sept. 24-27, 2002Numerical Python2 Since Python is an interpreted language, we need better performance particularly when."— Presentation transcript:

1 Numerical Python Tom LeFebvre

2 Sept. 24-27, 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

3 Sept. 24-27, 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

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

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

6 Sept. 24-27, 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

7 Sept. 24-27, 2002Numerical Python7 Creating Special Arrays >>> BunchaOnes = ones((4, 4)) >>> BunchaOnes >>> BunchaZeros = zeros((4, 4)) >>> BunchaZeros

8 Sept. 24-27, 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

9 Sept. 24-27, 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

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

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

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

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

14 Sept. 24-27, 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)

15 Sept. 24-27, 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

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


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

Similar presentations


Ads by Google