from numpy import *
if __name__ == '__main__':'''flatten 用于数组'''a = array([[1,2,3,4,5],[3,4,5,6,7],[1,4,5,6,74],[23,4,5,6,7]])print(type(a))print(a.flatten())'''[ 1 2 3 4 5 3 4 5 6 7 1 4 5 6 74 23 4 5 6 7]'''print(type(a.flatten()))'''flatten 用于矩阵'''b = mat([[2,3,4],[3,4,5],[4,5,6]])print(b)print(type(b))print(b.flatten())print(type(b.flatten()))print(b.flatten().A)#flatten之后矩阵变成了数组print(b.flatten().A[0])print(type(b.flatten().A[0]))'''<class 'numpy.ndarray'>[ 1 2 3 4 5 3 4 5 6 7 1 4 5 6 74 23 4 5 6 7]<class 'numpy.ndarray'>[[2 3 4][3 4 5][4 5 6]]<class 'numpy.matrixlib.defmatrix.matrix'>[[2 3 4 3 4 5 4 5 6]]<class 'numpy.matrixlib.defmatrix.matrix'>[[2 3 4 3 4 5 4 5 6]][2 3 4 3 4 5 4 5 6]<class 'numpy.ndarray'>'''flatten不能用于列表
转载于:https://www.cnblogs.com/flyingcr/p/10326917.html