Basic Setup

from numpy import *

To import all numpy functions

Variables

Declaration

#Declare a Pynum array with 10 elements
a = arange(1-10)

#Initialize it immediatly
a = ([1,2,3])

#Initialize it as explicit float
a = array([9,6,5,1],dtype=float)

#Or do the same with arange
a = arange(1-5,dtype=float)    

Selection

#print out the second element
a[2]

#print out element 1 to 3, excluding the last
a[1:3]

Matrix

Creation

#Creates a 4 x 4 identity matrix
a = eye(4)

#To create a matrix filled with ones use
a = ones(3,4)

#Maps a to the diagonal line of a matrix
b = diag(a)

Operations

#Scalar Product
b=dot(a,a)

#Outer Product
b=outer(a,a)

Selection

#choose the whole column from a in row 1
s2 = a[:,1]

#To explicitly set a value
a[2,3] = 5

Properties

#Shows the type of a
type(a)

#Shows the length of a 
a.shape

Additional Information

# "#" is used for comments

# Potency is realized with **
a = 4 ** 2

# Intendation is used for scoping
for i in range(1,5):
 print i

#functions are defined like this
def square(x):
 y = x * x
 return y

print quadrat(5)