MathGroup Archive 2009

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

Search the Archive

Re: Importing previously exported irregular lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg102963] Re: Importing previously exported irregular lists
  • From: David Bailey <dave at removedbailey.co.uk>
  • Date: Thu, 3 Sep 2009 05:39:54 -0400 (EDT)
  • References: <200908311033.GAA06953@smc.vnet.net> <h7l8q5$34k$1@smc.vnet.net>

Elton Kurt TeKolste wrote:
> I tried to save some data that is in the form of a list of list of list,
> where the lengths of the lists in top and second layer may vary.
> 
> In spite of the claims in the Mathematica help ("Import["file","Table"]
> will handle many kinds of tabular data, automatically deducing the
> details of the format whenever possible. "), it seems to be difficult to
> save such a list and retrieve it.
> 
> My problem is illustrated by the following toy example.  It seems that
> the import of a previously exported table interprets inner lists as
> strings.  Any suggestions?   
> 
> In[194]:= test = {{{5.7, 4.3}}, {4}}
> Out[194]= {{{5.7, 4.3}}, {4}}
> 
> In[195]:= Export["out.dat", test]
> Out[195]= "out.dat"
> 
> In[196]:= test2 = Import["out.dat"]
> Out[196]= {{"{5.7,", "4.3}"}, {4}}
> 
> In[197]:= test2 == test
> Out[197]= False
> 
> In[198]:= #[[1, 1]] & /@ {test, test2}
> Out[198]= {{5.7, 4.3}, "{5.7,"}
> 
> In[199]:= Head[#[[1, 1]]] & /@ {test, test2}
> Out[199]= {List, String}
> 
> *************************************
> Note: it works fine if the lists are "regular"
> 
> In[208]:= test = {{5.7, 4.3}, {4, 99}}
> Out[208]= {{5.7, 4.3}, {4, 99}}
> 
> In[209]:= Export["out.dat", test]
> Out[209]= "out.dat"
> 
> In[210]:= test2 = Import["out.dat"]
> Out[210]= {{5.7, 4.3}, {4, 99}}
> 
> In[211]:= test2 == test
> Out[211]= True
> Regards,
> Kurt Tekolste
> 
> 
If you just need to save an expression (of any kind) in a file to be 
read back later, use Save, and read it back with Get. Import is more 
appropriate for files that have been generated in some format outside of 
Mathematica.

David Bailey
http://www.dbaileyconsultancy.co.uk


  • Prev by Date: Re: Bug in Solve?
  • Next by Date: Re: Bug in Solve?
  • Previous by thread: Importing previously exported irregular lists
  • Next by thread: BoxWhiskerPlot - BoxLabels and FrameTicks won't work together