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.]]) 
Jiminion
  • 5,080
  • 1
  • 31
  • 54
Nilani Algiriyage
  • 32,876
  • 32
  • 87
  • 121

2 Answers2

2

Just use tolist()

x = np.array([[0, 0]]).tolist()
emesday
  • 6,078
  • 3
  • 29
  • 46
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]]
Maxime Lorant
  • 34,607
  • 19
  • 87
  • 97