Bottom Page

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,
Quote
#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
Quote
#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 ?
Quote
#4
.astype()?

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

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Formula with elements of list - If-condition regarding the lists elements lewielewis 2 639 May-08-2020, 01:41 PM
Last Post: nnk
  Indirectlty convert string to float in JSON file WBPYTHON 6 294 May-06-2020, 12:09 PM
Last Post: WBPYTHON
  define certain array elements+display with digits lukezo 0 182 Apr-10-2020, 05:03 PM
Last Post: lukezo
  ValueError: could not convert string to float RahulSingh 3 382 Apr-09-2020, 02:59 PM
Last Post: dinesh
  convert a list of string+bytes into a list of strings (python 3) pacscaloupsu 4 2,499 Mar-17-2020, 07:21 AM
Last Post: markfilan
  Convert dataframe string column to numeric in Python darpInd 1 329 Mar-14-2020, 10:07 AM
Last Post: ndc85430
  How to prepare a NumPy array which include float type array elements subhash 0 224 Mar-02-2020, 06:46 AM
Last Post: subhash
  convert 'A B C' to numpy float matrix rezabma 4 235 Feb-27-2020, 09:48 AM
Last Post: rezabma
  ValueError: could not convert string to float: '4 AVENUE' Kudzo 4 866 Jan-26-2020, 10:47 PM
Last Post: Kudzo
  numpy.where array search for string in just one coordinate adetheheat 1 358 Jan-09-2020, 07:09 PM
Last Post: paul18fr

Forum Jump:


Users browsing this thread: 1 Guest(s)