Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #15196

Re: Export Import Array

From Bob Hanlon <hanlonr357@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Export Import Array
Date 2013-07-18 06:43 +0000
Message-ID <ks82pl$jna$1@smc.vnet.net> (permalink)
References <20130717055004.0214169C9@smc.vnet.net>
Organization Time-Warner Telecom

Show all headers | View raw


One way:

steps = {.05, .1, .2, .25};


{dx, dy, dz} = Table[RandomChoice[steps], {3}]


{0.2, 0.05, 0.1}


vectors = Table[{x, y, z},
   {x, -1, 1, dx},
   {y, -1, 1, dy},
   {z, -1, 1, dz}];


dim = Dimensions[vectors]


{11, 41, 21, 3}


Export["vectors.csv", Flatten[vectors, 2]];


vectors2 = Fold[Partition[#1, #2] &,
   Import["vectors.csv"],
   dim // Most // Rest // Reverse];


vectors == vectors2


True



Bob Hanlon




On Wed, Jul 17, 2013 at 1:50 AM, graser <graser@gmail.com> wrote:

> Dear Mathematica Users!
>
> I have a question for you about Exporting and Importing array.
> Let's say there is a array (or vector) like,
> vectors =
>   Table[{x, y, z}, {x, -1, 1, .25}, {y, -1, 1, .25}, {z, -1, 1, .25}];
>
> If I export vectors as "XLS" format and import the XLS file,
> TT= Import["vector.xls", "XLS"];
>
> Some funny thing happen like
> TT[[1, 1, 1]] should be {-1,-1,-1} so that If I do TT[[1, 1, 1,1]] , it
> should give -1.
>
> But instead of that, TT[[1, 1, 1]]  gives a string as "{-1., -1., -1.}" .
>
> If I export vectors as "Table" format and import the table file,
> TR= Import["vector.data", "Table"];
> It gives  something like.. {"{{-1.,", "-1.,", "-1.},",....  All double
> comma.
>
>
> Do you know how to properly export vector (or array) ?
>
> And if I import string instead of vecotor like TT, How to convert TT like
> string to array?
> "{-1., -1., -1.}"  -> {-1,-1,-1}
>
> Thanks!
>
>
>
>

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: Export Import Array Bob Hanlon <hanlonr357@gmail.com> - 2013-07-18 06:43 +0000

csiph-web