Question: Problem 3 . Recall that the Vector data type represents a vector and supports the following API: 2 vector.Vector Vector ( a ) constructs a

Problem 3. Recall that the Vector data type represents a vector and supports the following API:
2 vector.Vector
Vector(a) constructs a new vector v with Cartesian coordinates taken from the list a
v[i] returns the ith coordinate of v
v + w returnsthesumofv andw
v - w returns the difference of v and w
v.scale(alpha) returns the scalar product of float alpha and v
v.dot(w) returns the dot product of v and w
v.direction() returns the unit vector in the same direction as v
abs(v) returns the magnitude of v
len(v) returns the dimensions of v
str(v) returns a string representation of v
Now suppose you have a 5-dimensional vector v =(1,3,2,6,4).
a. What is the syntax for creating a Vector object v that represents the vector v?
A v = Vector(-1,3,2,6,4)
B v =[-1,3,2,6,4]
C v = Vector.__init__([-1,3,2,6,4])
D v = Vector([-1,3,2,6,4])
E v = Vector.__init__(-1,3,2,6,4)
b. What is the syntax for computing the dot product of the vectors v and 2v?
A v.dot(Vector.scale(v,2))
B v.dot(2* v)
C Vector.dot(Vector.scale(v,2))
D Vector.dot(v,2* v)
E v.dot(v.scale(2))
c. What is the dot product of the vectors v and 2v? d. What does the code abs(v) translate to internally?
A v.__abs__(self)
B v.__abs__()
C __abs__(self, v)
D v.abs()
E self.__abs__(v)
e. What does abs(v) return?
f. Suppose x and y are two Vector objects. What does the code x + y translate to internally?
A Vector.__add__(y, x)
B Vector.__add__(x, y)
C x.__add__(y)
D __add__(x, y)
E y.__add__(x)
g. What does len(v) return?
h. What does the code str(v) translate to internally?
A v.__str__(self)
B v.str()
C self.__str__(v)
D v.__str__()
E str(self, v)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Finance Questions!