How can i convert a string to an array with elements type float 64 - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: How can i convert a string to an array with elements type float 64 (/thread-3287.html) |
How can i convert a string to an array with elements type float 64 - zoya2385 - May-11-2017 Hello, I have to convert the variable input to an array with dtype float64. The variable input is as below: [code]print input [ 6.36505950e+10 6.36505951e+10 6.32830000e+01 ..., 0.00000000e+00 0.00000000e+00 0.00000000e+00] FV = np.array(input) print FV [ 6.36505950e+10 6.36505951e+10 6.32830000e+01 ..., 0.00000000e+00 0.00000000e+00 0.00000000e+00] print type (FV) <type 'numpy.ndarray'> print FV.dtype |S109[/code]As you can see, elements type of FV array is |S109. How can i convert elements type to float64 ? I tried : FV = np.array(featureVector, dtype=np.float64)but it doesn't work. Note: the print do not display all elements of input variable (see the ellipsis ...) because there are many elements (38 elements). thank you for your help, RE: How can i convert a string to an array with elements type float 64 - wavic - May-11-2017 input is reserved Python word - built-in function. You are overwriting it.
RE: How can i convert a string to an array with elements type float 64 - zoya2385 - May-11-2017 Ok i'll replace "input" by "test". it's the same result. print test [ 6.36505950e+10 6.36505951e+10 6.32830000e+01 ..., 0.00000000e+00 0.00000000e+00 0.00000000e+00] FV = np.array(test) print FV [ 6.36505950e+10 6.36505951e+10 6.32830000e+01 ..., 0.00000000e+00 0.00000000e+00 0.00000000e+00] print type (FV) <type 'numpy.ndarray'> print FV.dtype |S109How can i set elements type as float64 ? RE: How can i convert a string to an array with elements type float 64 - nilamo - May-11-2017 .astype()? https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.astype.html |