Python Forum
How can i convert a string to an array with elements type float 64
Thread Rating:
  • 3 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can i convert a string to an array with elements type float 64
#1
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,
Reply
#2
input is reserved Python word - built-in function. You are overwriting it.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
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 ?
Reply
#4
.astype()?

https://docs.scipy.org/doc/numpy/referen...stype.html
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Numpy] How to store different data type in one numpy array? water 7 537 Mar-26-2024, 02:18 PM
Last Post: snippsat
Sad ValueError: could not convert string to float badju 0 4,318 Jul-01-2021, 12:13 AM
Last Post: badju
  Join each list elements with string in other DF handy88 0 1,535 Feb-09-2021, 07:00 PM
Last Post: handy88
  type error array BrianPA 2 2,389 Jan-17-2021, 01:48 PM
Last Post: BrianPA
  Formula with elements of list - If-condition regarding the lists elements lewielewis 2 2,736 May-08-2020, 01:41 PM
Last Post: nnk
  Indirectlty convert string to float in JSON file WBPYTHON 6 5,937 May-06-2020, 12:09 PM
Last Post: WBPYTHON
  define certain array elements+display with digits lukezo 0 1,253 Apr-10-2020, 05:03 PM
Last Post: lukezo
  ValueError: could not convert string to float RahulSingh 3 4,180 Apr-09-2020, 02:59 PM
Last Post: dinesh
  convert a list of string+bytes into a list of strings (python 3) pacscaloupsu 4 10,828 Mar-17-2020, 07:21 AM
Last Post: markfilan
  Convert dataframe string column to numeric in Python darpInd 1 2,297 Mar-14-2020, 10:07 AM
Last Post: ndc85430

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020