Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: how to get string in sci. notation to a number?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg124096] Re: how to get string in sci. notation to a number?
  • From: "Oleksandr Rasputinov" <oleksandr_rasputinov at hmamail.com>
  • Date: Mon, 9 Jan 2012 03:14:00 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <jb2hum$5e0$1@smc.vnet.net> <op.v5phrszkqcgwdu@core2.lan>

On Tue, 29 Nov 2011 11:48:54 -0000, Oleksandr Rasputinov  
<oleksandr_rasputinov at hmamail.com> wrote:

> On Tue, 29 Nov 2011 12:07:50 -0000, 1.156 <rob at piovere.com> wrote:
>
>> I've been able to get a text file with data into a list of strings
>> of the following form:
>>
>> {{"4.998865e+000", "9.564453e-006"},
>>   {"5.630450e+000", "9.194384e-006"},
>>   {"6.113276e+000", "8.134170e-006"}}
>>
>> After many hours I've really gotten nowhere except that it's most
>> likely done with ToExpression which works fine with simple decimal
>> numbers in string form. Must I really split up the strings, suck out the
>> exponents, and then multiply them out to be able to use these numbers in
>> a ListPlot?
>> Any hints would be appreciated.
>
> In place of "e", Mathematica uses "*^". When reading output from a  
> Python program into Mathematica for analysis, I have used StringReplace  
> to convert to valid Mathematica syntax followed by ToExpression; this  
> can be faster and more convenient than Import in certain cases. However,  
> if you are happy with your current approach and just want to finish the  
> job, you can use e.g.:
>
> lst = {
>   {"4.998865e+000", "9.564453e-006"},
>   {"5.630450e+000", "9.194384e-006"},
>   {"6.113276e+000", "8.134170e-006"}
> }
>
> Map[Sequence@@ImportString[#, "List", "Numeric" -> True] &, lst, {2}]
>
> {{4.99887, 9.56445*10^-6},
>   {5.63045, 9.19438*10^-6},
>   {6.11328, 8.13417*10^-6}}

Perhaps it is not worth reviving this old thread, but I noticed another  
way to perform this task which may be of interest given the relatively  
frequent requirement for importation of numbers in this format into  
Mathematica:

Map[Internal`StringToDouble, lst, {2}]

Internal`StringToDouble seems to work in Mathematica 7 and 8. It exists in  
version 5.2 but appears to do nothing. I didn't try version 6.



  • Prev by Date: Re: Re: SortBy for multiple key sorts
  • Next by Date: Re: Sorting coefficients
  • Previous by thread: Re: Linux uninstall
  • Next by thread: Re: For a variety of plotting experiences, maybe bugs?