Vectors as functions!!


In [1]:
from plotting import plot
L = [[2, 2], [3, 2], [1.75, 1], [2, 1], [2.25, 1], [2.5, 1], [2.75,
  1], [3, 1], [3.25, 1]]
plot(L,4)

In [2]:
#Quiz 2.4.4
def addn(u, v):
    return [x+y for (x,y) in zip(u,v)]
print addn([1,2,3], [3,2,1])


[4, 4, 4]

In [7]:
class Vec:
    def __init__(self, labels, function):
        self.D = labels
        self.f = function
    
def zero_vec(D):
    return Vec(D, {d:0 for d in D})
d = {1,2,3}
print zero_vec(d)


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-7-28483db105b2> in <module>()
      7     return Vec(D, {d:0 for d in D})
      8 d = {1,2,3}
----> 9 print zero_vec(d)

TypeError: zero_vec() takes exactly 2 arguments (1 given)

In [ ]: