0

I'm developing a software to create a matrix with this structure : [[2020-07-14 13:01:58.535695, 9.013799869442407, 989.5936121308639], [2020-07-14 14:40:05.144901, 59.27540855766542, 463.4158524443841]]

To build the first line , the array should contains : [2020-07-14 13:01:58.535695,2020-07-14 14:40:05.144901]

To concatenate these datetime I do this:

x_vet = []
        for z in range(self.n_samples):
            self.x_0 = datetime.now()
            totaltime = self.x_0 + timedelta(milliseconds = self.period)
            x_vet.append(self.x_0 + totaltime)
        self.signals_data.append(x_vet)

The error is:

TypeError: unsupported operand type(s) for +: 'datetime.datetime' and 'datetime.datetime'

So I've tried to do this in the code:

x_vet.append(str(self.x_0) + str(totaltime))

But with str() I get only 1 element like that: '2020-07-14 14:35:44.0007892020-07-14 14:35:44.010789'

I want to get this in x_vet : [2020-07-14 13:01:58.535695,2020-07-14 14:40:05.144901] Because the whole software is build to recognize x_vet as an array of 2 elements

This error appears only with datatime object, because at the start I've tried my program with float and was working and returned:

[[0.0, 9.013799869442407, 989.5936121308639], [0.01, 59.27540855766542, 463.4158524443841]]

1 Answer 1

1

Did you mean this?

x_vet = []

for z in range(self.n_samples):
    self.x_0 = datetime.now()
    totaltime = self.x_0 + timedelta(milliseconds = self.period)
    x_vet.append(totaltime)
self.signals_data.append(x_vet)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.