Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a TimeSeries class. This class should have two instance variables. The time instance variable should be able to contain multiple measurements of time, which

Create a TimeSeries class. This class should have two instance variables. The time instance variable should be able to contain multiple measurements of time, which you may assume to be numeric (i.e. int or float). The data instance variable should be able to contain multiple measurements of some data, which you may also assume to be numeric. The user should be able to pass lists containing the time and data measurements to the TimeSeries class on construction.

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 timeinstance 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

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

Hands On Database

Authors: Steve Conger

1st Edition

013610827X, 978-0136108276

More Books

Students also viewed these Databases questions