0

I'm confused of converting following numpy array

[[ 0.  1.  3.  0.  2.  3.  1.]
 [ 1.  0.  3.  1.  1.  2.  2.]
 [ 3.  3.  0.  3.  3.  3.  4.]
 [ 0.  1.  3.  0.  2.  3.  1.]
 [ 2.  1.  3.  2.  0.  1.  3.]
 [ 3.  2.  3.  3.  1.  0.  3.]
 [ 1.  2.  4.  1.  3.  3.  0.]]

in to list of lists as following?

([[ 0. , 1. , 3.  ,0. ,2.  ,3.  ,1.],
 [ 1. , 0. , 3. , 1.,  1. , 2. , 2.],
 [ 3.,  3. , 0.,  3. , 3.,  3. , 4.],
 [ 0. , 1. , 3.,  0. , 2. , 3.,  1.],
 [ 2. , 1.,  3. , 2.,  0. , 1.,  3.],
 [ 3. , 2.,  3. , 3. , 1. , 0. , 3.],
 [ 1. , 2.,  4. , 1. , 3.,  3. , 0.]]) 
1

2 Answers 2

2

Just use tolist()

x = np.array([[0, 0]]).tolist()
Sign up to request clarification or add additional context in comments.

Comments

2

Arrays has the method tolist():

>>> a = np.array([1, 2])
>>> a.tolist()
[1, 2]
>>> a = np.array([[1, 2], [3, 4]])
>>> list(a)
[array([1, 2]), array([3, 4])]
>>> a.tolist()
[[1, 2], [3, 4]]

1 Comment

Never thought it is just simple. Thanks.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.