Question: untitled hw09.py hw09.py 2 #### Arr88 #### def add (self, arr88): 4 Question 1: Add two Arr88s of the same length componentwise >>> arr88a =

 untitled hw09.py hw09.py 2 #### Arr88 #### def add (self, arr88):

untitled hw09.py hw09.py 2 #### Arr88 #### def add (self, arr88): 4 "Question 1:" Add two Arr88s of the same length componentwise >>> arr88a = Arr88([1, 2, 31) >arr88bArr88(14, 5, 6]) class Arr88): Arr88 is an object similar to Data 8 numpy arrays. Here the internel representation is a list 48 arr88a+ arr88b Arr88( [5, 7, 9]) >>> arr88a # We aren't mutating arr88a Arr88( [1, 2, 31) def init(self, values): 10 11 #This checks that all values are the same type, else it errors 52 12 arr88a Arr88( ['He', 'Wor', ''1) if len (values) > 1: 53 assert all([type (values [0]) == type (values [1]) for i in range(len(values))1) arr88a + arr88b 14 15 16 self.values values # DO NOT CHANGE THE-repr # This displays the Arr88 nicely in the terminal def-repr-(self): # Checks that the lengths are the same assert len (self) = len (arr88) "* YOUR CODE HERE return 18 19 59 60 return "Arr88(" + str(self.values) + def len_(self): 62 def mul_(self, arr88): "Get the length of the Arr88 >arr88 Arr88 ( 11, 2, 3]) >len(arr88) Multiply two Arr88s of the same length componentwise >>> arr88a = Arr88([1, 2, 31) >>> arr88b = Arr88([4, 5, 61) arr88a arr88b Length0 for x in self.values: 67 68 69 Arr88( [4, 10, 18]) >>> arr88a # We aren't mutating arr88a Arr88( [1, 2, 3]) 28 29 Length 1 return length def item(self, i): >>> arr88b = Arr88 ([10, 1, 51) >arr88a arr88b 32 Get the item of the Arr88 at index i >arr88 Arr88(11, 2, 3]) >arr88.item(1) 73 35 # Checks that the lengths are the same assert len (self) len(arr88) 76 >arr88.item(0) 78 79 o YOUR CODE HERE o" return if self._len_(Oi: else: -add--(self, 40 print("Invalid index") def negate(self): return self.values [i] Negate an Arr88 with mutation >arr88aArr88( [1, 2, 3]) def arr88): arr88b Arr88( [4.0, -5.5, 0.0]) Add two Arr88s of the same length componentwise >arr88aArr88([1, 2, 3]) >arr88bArr88([4, 5, 6]) 86 >>arr88a.negate() arr88a 47 Arr88( [-1, -2, -3])

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 Databases Questions!