python tolist()方法

将数组或者矩阵转换成列表,如下:

 

>>> from numpy import *
>>> a1 = [[1,2,3],[4,5,6]] #列表
>>> a2 = array(a1) #数组
>>> a2
array([[1, 2, 3],
       [4, 5, 6]])
>>> a3 = mat(a1) #矩阵
>>> a3
matrix([[1, 2, 3],
        [4, 5, 6]])
>>> a4 = a2.tolist()
>>> a4
[[1, 2, 3], [4, 5, 6]]
>>> a5 = a3.tolist()
>>> a5
[[1, 2, 3], [4, 5, 6]]
>>> a4 == a5
True

 

posted on 2018-05-15 19:33  Aaron12  阅读(50217)  评论(0编辑  收藏  举报

导航