Convert 2d numpy array into list of lists [duplicate]
You can simply cast the matrix to list with matrix.tolist()
, proof:
>>> import numpy>>> a = numpy.ones((2,4))>>> aarray([[ 1., 1., 1., 1.], [ 1., 1., 1., 1.]])>>> a.tolist()[[1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0]]>>> type(a.tolist())<type 'list'>>>> type(a.tolist()[0])<type 'list'>