Python Forum

Full Version: How can i convert a string to an array with elements type float 64
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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,
input is reserved Python word - built-in function. You are overwriting it.
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
|S109
How can i set elements type as float64 ?