I have a numpy list, type of its element is numpy.float64 and I would like to convert all element of the list to float.
This is the print out of the list:
[array([ -7.19244777e+24, 3.32768299e-02, -7.19249216e+24], dtype=float32),
array([ -8.87044985e+25, 1.46775544e-01, -8.87068228e+25], dtype=float32),
array([ 0.61927807, -0.16575921, 0.98002648], dtype=float32),
array([ 0.63426137, -0.15838303, 0.97730571], dtype=float32)]
I could convert each element from numpy.float to float with following code.
mtx = []
for i in range(len(centroids)):
row = []
for j in range(len(centroids[i])):
row.append(np.asscalar(centroids[i][j]))
mtx.append(row)
I am wondering is there any one-liner or utility method to convert elements of whole list from numpy.float64 to float ?
Same question for string and other data types.
np.asarray(centroids, dtype=float)? - N. Wouda