python - Converting a numpy multidimensional array to list -
i new python. looked @ other similar topics not answering want do. here outcome:
coslist[1:4] out[94]: [array([[ 0.7984719]]), array([[ 0.33609957]]), 0] this want:
coslist=[0.7984719,0.33609957,0] i tried this:
tolist=list(coslist) tolist[1:3] out[98]: [array([[ 0.7984719]]), array([[ 0.33609957]])] and this:
y=np.array(val).ravel().tolist() y[1:4] out[99]: [array([[ 0.7984719]]), array([[ 0.33609957]]), 0] as see of them want. appreciated.
there's built-in method of numpy array.
coslist = [numpy.array([[ 0.7984719]]), numpy.array([[ 0.33609957]]), 0] coslist = [x.tolist()[0][0] if type(x)==numpy.ndarray else x x in coslist] type(coslst) # should print <type 'list'> lst # should print list of lists
Comments
Post a Comment