tolist() 函数

用于将数组或矩阵转换成列表

实例:

import numpy as np
a = np.ones(5)  # array([1., 1., 1., 1., 1.])
a.tolist()  # [1.0, 1.0, 1.0, 1.0, 1.0]
b = [[1, 2, 3], [0, 9, 8, 0]]
c = np.mat(b)  # matrix([[list([1, 2, 3]), list([0, 9, 8, 0])]])
c.tolist()  # [[1, 2, 3], [0, 9, 8, 0]]

在对数据集预处理时常会用到

原文地址:https://www.cnblogs.com/alivinfer/p/12558726.html