在numpy数组上应用list()与调用tolist()有什么区别?在
我检查了两个输出的类型,它们都显示我得到的结果是一个list,但是,输出看起来并不完全相同。是因为list()不是numpy特定的方法(即可以应用于任何序列),而{}是特定于numpy的,在这种情况下,它们返回的是相同的东西?在
输入:points = numpy.random.random((5,2))
print "Points type: " + str(type(points))
输出:
^{pr2}$
输入:points_list = list(points)
print points_list
print "Points_list type: " + str(type(points_list))
输出:[array([ 0.15920058, 0.60861985]), array([ 0.77414769, 0.15181626]), array([ 0.99826806, 0.96183059]), array([ 0.61830768, 0.20023207]), array([ 0.28422605, 0.94669097])]
Points_list type: 'type 'list''
输入:points_list_alt = points.tolist()
print points_list_alt
print "Points_list_alt type: " + str(type(points_list_alt))
输出:[[0.15920057939342847, 0.6086198537462152], [0.7741476852713319, 0.15181626186774055], [0.9982680580550761, 0.9618305944859845], [0.6183076760274226, 0.20023206937408744], [0.28422604852159594, 0.9466909685812506]]
Points_list_alt type: 'type 'list''