A quick peek at SciPy

"There are a great many people in the country today, who through no fault of their own, are sane." -- The Silly Vicar Sketch

Author: Stéfan van der Walt
Date: 14/02/2007

Pieces of the Puzzle

NumPy

Constructing arrays

Provides a new class -- N-dimensional arrays.

import numpy as N
x = N.array([1,2,3])
x = N.array([1,2,3], dtype=int)
x = N.zeros((50,50,3), dtype=float)

Note the concept of a data type -- int, float, str, object, record.

>>> import numpy as N
>>> x = N.array([1,2,3])
>>> y = N.array([3,2,1])
>>> x+y
array([4, 4, 4])

Array Slicing

Way to get hold of sub-arrays:

x = N.random.rand((5,5))
x[0,0]
x[0,:]
x = N.random.rand((5,5,3))
x[0]
x[1,...]

Array shape and type manipulation

Change shape:

x = N.arange(12)
x.reshape((4,3))
x.flat

Change data type:

x.astype(float)

Extending numpy

SciPy

How to find your way around SciPy

Documentation:

Pretty pictures with matplotlib

Demos

Testing your code

Peace of mind at the press of a button...

def hello():
    
return 'hello'

if __name__ == '__main__':
    
from numpy.testing import *

    
class test_hello(NumpyTestCase):
        
def test_string(self):
            
assert_equal(hello(), 'hello')

    
NumpyTest().test()

Version control

bzr demo

Read more in Software Carpentry course.

Installation

Further resources