Converting list of arrays into list of lists in Python

Question:

I have a list I which contains numpy arrays. I want to convert these arrays into lists as shown in the current and expected outputs.

import numpy as np
I=[np.array([[0, 1],
        [0, 2],
        [1, 3],
        [4, 3],
        [2, 4]]),
 np.array([[0, 1],
        [0, 2],
        [1, 3],
        [4, 3],
        [3, 4],
        [2, 5]])]

for i in range(0,len(I)):
    arI1=[]
    I1=I[i].tolist()
    arI1.append(I1)
    I1=list(arI1)
    print(I1)

The current output is

[[[0, 1], [0, 2], [1, 3], [4, 3], [3, 4], [2, 5]]]

The expected output is

[[[0, 1], [0, 2], [1, 3], [4, 3], [2, 4]],
[[0, 1], [0, 2], [1, 3], [4, 3], [3, 4], [2, 5]]]
Asked By: Klimt865

||

Answers:

You can use numpy:

import numpy as np

I1 = np.array(I1, dtype=object).tolist()
Answered By: mauro
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.