Numerical Python - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

Numerical Python

Description:

Advantages: High-level language allows very fast development ... You must import the Numeric module before using Numerical Python. import Numeric. or ... – PowerPoint PPT presentation

Number of Views:61
Avg rating:3.0/5.0
Slides: 17
Provided by: Mar5544
Category:
Tags: numerical | python | use

less

Transcript and Presenter's Notes

Title: Numerical Python


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

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

4
Importing Numeric
  • You must import the Numeric module before using
    Numerical Python
  • import Numeric
  • or

gtgtgt from Numeric import
5
Making Numeric Arrays
gtgtgt a array (0, 1, -2, 6, -5) gtgtgt a
gtgtgt b arrayrange(10) gtgtgt b
6
Multi-dimensional Arrays
  • gtgtgt a array(1, 2, 3, 4, 5, 6, 7, 8,
    9)
  • gtgtgt a

gtgtgt a.shape
7
Creating Special Arrays
gtgtgt BunchaZeros zeros((4, 4)) gtgtgt BunchaZeros
gtgtgt BunchaOnes ones((4, 4)) gtgtgt BunchaOnes
8
Manipulating Arrays
gtgtgt BunchaThrees BunchaOnes 3 gtgtgt BunchaThrees
gtgtgt f arrayrange(0, 100, 5) gtgtgt c (f - 32)
5 / 9 gtgtgt c
gtgtgt c (f - 32) 5 / 9.0 gtgtgt c
9
Array Slicing
  • Slicing Operator

arraystart 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
Slicing Arrays
gtgtgt a arrayrange(10) gtgtgt a gtgtgt a2 gtgtgt
a04 gtgtgt a-1 gtgtgt a-1 gtgtgt a2 -999 gtgtgt a
11
Slicing Multi-dimensional Arrays
gtgtgt b reshape(arrayrange(9), (3, 3)) gtgtgt b
gtgtgt b0, 0 gtgtgt b 2, 1 gtgtgt b-1, -1
12
Slicing Multi-dimensional Arrays
gtgtgt b gtgtgt b01, 0
gtgtgt b02, 02 gtgtgt b
gtgtgt b2 gtgtgt b-1 gtgtgt b-1, -1
13
Some Useful Functions
gtgtgt a arrayrange(10) gtgtgt a gtgtgt add.reduce(a)
14
Logical Functions - makes 0s or 1s
gtgtgt b reshape(arrayrange(25), (5, 5)) gtgtgt b
gtgtgt less (b, 12)
gtgtgt greater(b, 7) gtgtgt less_equal(b, 10)
15
Array Functions - where()
where is the Numerical Python if statement
where(condition, true value, false value)
gtgtgt b gtgtgt c where (less(b, 12), 0, b) gtgtgt c
Note 0 is false, everything else is true
16
Array Functions - clip()
clip(array, min, max)
gtgtgt b gtgtgt d clip(b, 5, 15) gtgtgt d
Write a Comment
User Comments (0)
About PowerShow.com