MathGroup Archive 2009

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

Search the Archive

Importing previously exported irregular lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg102917] Importing previously exported irregular lists
  • From: "Elton Kurt TeKolste" <tekolste at fastmail.us>
  • Date: Wed, 2 Sep 2009 04:02:49 -0400 (EDT)
  • References: <200908311033.GAA06953@smc.vnet.net>

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



  • Prev by Date: Re: Faster alternative to AppendTo?
  • Next by Date: Re: Replace in operators
  • Previous by thread: Re: Bug in Solve?
  • Next by thread: Re: Importing previously exported irregular lists