0
$\begingroup$

I exported a some of my data to a file, the data looks like this before the export

Dimensions[mydata]
{129}

Dimensions[mydata[[1]]]
Dimensions[mydata[[3]]]
 {36, 2}
 {16, 2}

mydata[[1, 5]]
mydata[[1, 5, 1]]
 {4.94378, 400.06}
 4.94378

Export["mydata.csv", mydata];

When I import it this is what it looks like:

myimportdata = Import["mydata.csv"];

Dimensions[myimportdata]
 {129}

Dimensions[myimportdata[[1]]]
Dimensions[myimportdata[[3]]]
 {36}
 {16}

myimportdata[[1, 5]]
myimportdata[[1, 5, 1]]
 {4.943784497, 400.06}
 Part specification {{{0, 0},{0.000345398, 0.03},{4.004763899, 200.02},{4.845128134, 200.11},

How can I fix this? So far I have tried Flatten and Partition but that didn't work. Is it treating the in inner pairs as a string? Any help would be great.

$\endgroup$
  • $\begingroup$ Is it possible to save a multidimensional dataset to CSV? I thought CSV would just be for a 2D array, just rows and columns, but clearly I'm wrong since your imported data has more than that. Can we have a small subset of mydata to work with? $\endgroup$ – Jason B. Dec 4 '15 at 15:41
  • $\begingroup$ Here you go: {{0, 0}, {0.000345398, 0.03}, {4.00476, 200.02}, {4.84513, 200.11}, {4.94378, 400.06}, {7.2857, 447.27}}, {{0, 0}, {0.000126261, 0.03}, {1.98535, 1.*10^6}, {2.93083, 1.*10^6}}, {{0, 0}, {0.000152619, 0.03}, {2.27639, 200.02}, {2.51146, 200.11}, {2.8589, 400.06}, {3.44741, 1.*10^6}}, {{0, 0}, {0.000086549, 0.03}, {1.27432, 200.02}, {2.8542, 3.93865*10^6}, {2.99701, 7.5813*10^6}} Ok whats the recommended format to export this data? $\endgroup$ – Phymonkey Dec 4 '15 at 16:11
  • $\begingroup$ @MikeLimaOscar, That did it thanks! $\endgroup$ – Phymonkey Dec 4 '15 at 16:20
4
$\begingroup$

Since your array has more than two dimensions (and is not full dimensional) Export writes the "extra dimensions" as strings. A MWE:

d = {Table[a + b, {a, 2}, {b, 2}], Table[a + b, {a, 3}, {b, 2}]}

{{{2, 3}, {3, 4}}, {{2, 3}, {3, 4}, {4, 5}}}

Dimensions[d]
Dimensions /@ d

{2}

{{2, 2}, {3, 2}}

No surprises there!

Export["mydata.csv", d];
FilePrint[%]

"{2, 3}","{3, 4}"

"{2, 3}","{3, 4}","{4, 5}"

You can read the data in using:

Import["mydata.csv"] /. x_String :> ToExpression[x]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.