Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone help me solve this Python Question? I'm not sure why I'm getting the assertion error. class Vector: def __init__(self, v): # replace with

Can someone help me solve this Python Question?

I'm not sure why I'm getting the assertion error.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

class Vector: def __init__(self, v): # replace with your body if type(v) != list: raise TypeError for e in v: if type(e) not in (int, float): raise TypeError

self.v = v def dim(self): return len(self.v) def __getitem__(self, i): if 1 Question A2: Defining Vectors (9 points) Define class vector for n-dimensional vectors as follows: Vector(1) : Creates a new vector with dimension len (1) from list 1 of numbers; raises TypeError if l is not a list or not all of its elements are of type int or float .v.dim) Returns the dimension (length) of the vector. . v. getitem (i): Returns the -th component of the vector, where components are indexed starting from 1 ; raises 1ndexError ?f ? ?s less than 1 or greater than the dimension of the vector. v. setitem (i, x) : Sets the 1-th component of vector v to x, where components are indexed starting from 1; raises 1ndexError if ? ?S less than 1 or greater than the dimension of the vector. v. repr v.add if other is of a different dimension. v. Vector or if other is of a different dimension. ?: Returns the canonical string representation of the vector, see the example below. (other): Returns a new vector that is the component-wise sum of v and other; raises ValueError if other is not of type Vector or . . sub (other) : Returns a new vector that is the component-wise substraction of v and other; raises ValueError if other is not of type . . v. mul (other If other is of type int or float, returns a new vector resulting from the scalar multiplication of v with other, , i.e. with each component of v multiplied by scalar. If other is of type Vector, returns the dot product of v and other, which is the sum of the products of the corresponding components, raises ValueError if other is of different dimension in this case. If the type of other is none of Vector, int, float, raises AssertionError. . v. rmul (other Defined exactly like v. mul (other) . v. equal (self, other): Returns True if the values of the vector equals the values of other and are in the same order Python uses the following equivalent notations: v._getitem--( i ) str(v) v + otherv._add (other) v- otherv. sub (other) v * other = v. mul_ ( other) other * v = v.-.rmul. _ ( other) if other. mul--(v) is not defined - V. str ( equal (other) Question A2: Defining Vectors (9 points) Define class vector for n-dimensional vectors as follows: Vector(1) : Creates a new vector with dimension len (1) from list 1 of numbers; raises TypeError if l is not a list or not all of its elements are of type int or float .v.dim) Returns the dimension (length) of the vector. . v. getitem (i): Returns the -th component of the vector, where components are indexed starting from 1 ; raises 1ndexError ?f ? ?s less than 1 or greater than the dimension of the vector. v. setitem (i, x) : Sets the 1-th component of vector v to x, where components are indexed starting from 1; raises 1ndexError if ? ?S less than 1 or greater than the dimension of the vector. v. repr v.add if other is of a different dimension. v. Vector or if other is of a different dimension. ?: Returns the canonical string representation of the vector, see the example below. (other): Returns a new vector that is the component-wise sum of v and other; raises ValueError if other is not of type Vector or . . sub (other) : Returns a new vector that is the component-wise substraction of v and other; raises ValueError if other is not of type . . v. mul (other If other is of type int or float, returns a new vector resulting from the scalar multiplication of v with other, , i.e. with each component of v multiplied by scalar. If other is of type Vector, returns the dot product of v and other, which is the sum of the products of the corresponding components, raises ValueError if other is of different dimension in this case. If the type of other is none of Vector, int, float, raises AssertionError. . v. rmul (other Defined exactly like v. mul (other) . v. equal (self, other): Returns True if the values of the vector equals the values of other and are in the same order Python uses the following equivalent notations: v._getitem--( i ) str(v) v + otherv._add (other) v- otherv. sub (other) v * other = v. mul_ ( other) other * v = v.-.rmul. _ ( other) if other. mul--(v) is not defined - V. str ( equal (other)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 11 The Ultimate Database For Cloud Analytics And Mobile

Authors: John Campbell, Chris Crone, Gareth Jones, Surekha Parekh, Jay Yothers

1st Edition

1583474013, 978-1583474013

More Books

Students also viewed these Databases questions

Question

Understand how to design effective service guarantees.

Answered: 1 week ago

Question

Know when firms should not offer service guarantees.

Answered: 1 week ago