Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have array as list item inside a list that I want to convert into list later on. Code below is a result from looping over a and b.

Output

>>> 
[[2, 0], [0, 0]]
[array([5, 7]), array([5, 5])]
[[1, 0, 2], [0, 0, 0], [1], [1]]
[array([5, 6, 4]), array([6, 6, 6]), array([3]), array([3])]
[[1, 0], [1, 0]]
[array([4, 5]), array([4, 5])]
>>> type(a)
<type 'list'>
>>> type(b)
<type 'list'>

I use tolist() function to convert them into list but there is one line that is not successful:

Output

>>> 
[[2, 0], [0, 0]]
[[5, 7], [5, 5]]
[[1, 0, 2], [0, 0, 0], [1], [1]]
[array([5, 6, 4]), array([6, 6, 6]), array([3]), array([3])]
[[1, 0], [1, 0]]
[[4, 5], [4, 5]]

Can anyone help me?

share|improve this question
1  
Your question is very unclear. Can you give a Minimal, Complete, and Verifiable example about what you want to do? or the code that you have tried so far? –  Kasra 2 hours ago

1 Answer 1

up vote 2 down vote accepted
from numpy import *

# Your original list of numpy arrays ...
b = [array([5, 7]), array([5, 5])]
# ... can be converted to list of lists
c = [list(x) for x in b]
share|improve this answer
    
It solved perfectly. Thanks. –  Xiong89 2 hours ago
    
@Xiong89 I am happy I could help you. –  dlask 2 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.