Skip to content
Advertisement

Formatting the print statement for multiple numpy arrays inside a dictionary Python

I am trying to modify my print statement within the for loop below so that it iterates through the list and the dictionary and prints the values of the first and second numpy arrays. In accordance to the Timeframes list. How can I modify the print statement below to get the Expected output below?

JavaScript

Expected Output:

JavaScript

Advertisement

Answer

If you make timeframes a numpy object with the same depth, you can stack the arrays together (or simply input them togeather).

In this case, let’s use vstack and transpose.

First we stack the arrays together:

JavaScript

data is now:

JavaScript

data.T is then:

JavaScript

Finally we can do a simple loop on the transposed data:

JavaScript

This gives us:

JavaScript

Note you can format out the output further by using a simple helper function:

JavaScript

Then you can edit your print statement line:

JavaScript

Which gives:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement