In [8]:
class vector:
    def __init__(self, a, b):
        self.x = a
        self.y = b
        return None

    def __add__(self, v):
        bla = vector(self.x + v.x, self.y + v.y)
        return bla

In [13]:
a = vector(1.1, 4.3)
b = vector(4.2,9.4352)
c = a + b #calling the add method, self is a and v is b.  it creates a new vector object.
print (c.x, c.y)


(5.300000000000001, 13.735199999999999)

Arrays

\begin{equation*} A = \left(\begin{matrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{matrix}\right) = \left(\begin{matrix} a_{1,1} & a_{1,2} & a_{1,3} \\ a_{2,1} & a_{2,2} & a_{2,3} \\ a_{3,1} & a_{3,2} & a_{3,3} \end{matrix}\right) \end{equation*}

This is a two-dimensional array because we can uniquely label the elements of the matrix by two numbers $i,j$ via the identification $a_{i,j}$.


In [57]:
import numpy as np

a = np.zeros((3,3), dtype = np.float)
b = np.ones((3,3), dtype = np.int)
I = np.array([[1,0,0],
              [0,1,0],
              [0,0,1]])
c = I*2*b
print a, type(a)
print b, type(b)
print c, type(I)


[[ 0.  0.  0.]
 [ 0.  0.  0.]
 [ 0.  0.  0.]] <type 'numpy.ndarray'>
[[1 1 1]
 [1 1 1]
 [1 1 1]] <type 'numpy.ndarray'>
[[2 0 0]
 [0 2 0]
 [0 0 2]] <type 'numpy.ndarray'>

In [ ]: