Question: # Python problem. ------------ Implement addition of TimeSeries objects. It is possible to add two TimeSeries objects together only if their time instance variables are

# Python problem.
------------
Implement addition of TimeSeries objects.
- It is possible to add two TimeSeries objects together only if their time instance variables are identical. If they are not, raise an informative ValueError.
- If the time instance variables are identical, then the result of adding two TimeSeries objects is a third TimeSeries with the same time instance variable and with data variable given by the sum of the data instance variables of the summands.
Demonstrate that the following test works:
t1 = TimeSeries([0.7, 2.4, 3.3], [0.5, -0.2, 0.2]) t2 = TimeSeries([0.7, 2.4, 3.3], [0.2, 0.1, -0.2]) t3 = t1 + t2 print(t3)
# printed output An object of class TimeSeries time: [0.7 2.4 3.3] data: [ 0.7 -0.1 0. ]
Demonstrate that this test also works:
t1 = TimeSeries([0.7, 2.4, 3.3], [0.5, -0.2, 0.2]) t2 = TimeSeries([0.0, 1.0, 2.0], [0.2, 0.1, -0.2]) t3 = t1 + t2
# time variables don't match, informative ValueError here
For full credit, your solution should require no for-loops or list comprehensions.
Hint: Your user will supply list input, but the stored instance variables don't have to be lists. It may be helpful to modify the __init__() method.
-----------
# Python problem.
Part C (10 points) Implement addition of TimeSeries objects. 1. It is possible to add two TimeSeries objects together only if their time instance variables are identical. If they are not, raise an informative ValueError 2. If the time instance variables are identical, then the result of adding two TimeSeries objects is a third TimeSeries with the same time instance variable and with data variable given by the sum of the data instance variables of the summands. Demonstrate that the following test works: t1 = TimeSeries ([0.7, 2. 4, 3.3], (0.5, -0.2, 0.2]) t2 = TimeSeries ([0.7, 2.4, 3.3], [0.2, 0.1, -0.2]) t3 = ti + t2 print(t3) # printed output An object of class TimeSeries time: [0.7 2.4 3.3] data: [ 0.7 -0.1 0. ] Demonstrate that this test also works: t1 = TimeSeries ([0.7, 2.4, 3.3], [0.5, -0.2, 0.2]) t2 = TimeSeries ([0.0, 1.0, 2.0], [0.2, 0.1, -0.2]) t3 = ti + t2 # time variables don't match, informative ValueError here For full credit, your solution should require no for-loops or list comprehensions. Hint: Your user will supply list input, but the stored instance variables don't have to be list s. It may be helpful to modify the __init__0 method. In [ ]: # first test here In [ ]: # second test here
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
