Handling data and creating arrays

Hello, I've started to use the convention of making dictionaries to hold my
datasets. But I haven't settled on an approach yet, and would like input
from people for how they a) handle their arrays of data, and b) how to
create pylab arrays from lists of lists, etc.

What I generally have is:

DataDict={var1:(x1,y1),var2:(x2,y2),var3:(x3,y3)} ; where the x and y's are
generally lists.

Now that's nice, because I can cycle through the DataDict.keys() to batch
plot, etc. But how can I convert the whole dict into a single array
(assuming the lengths are all equal)? I would like:

myArray=
x1a,y1a,x2a,y2a,x3a,y3a
x1b,y1b,x2b,y2b,x3b,y3b
...
x1,z,y1z,x2z,y2z,x3z,x3z

Where:
myArray[:,0]= x1a...x1z
myArray[0,:]=x1a,y1a,x2a,y2a,x3a,y3a

and so forth...
Thanks!

···

--
View this message in context: http://www.nabble.com/Handling-data-and-creating-arrays-tp17834278p17834278.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

DataDict={var1:(x1,y1),var2:(x2,y2),var3:(x3,y3)} ; where
the x and y's are generally lists.
Now that's nice, because I can cycle through the DataDict.keys() to batch
plot, etc. But how can I convert the whole dict into
a single array (assuming the lengths are all equal)?

Perhaps as below?
(Or the transpose.)
Alan Isaac

x1,y1,x2,y2 =np.random.random((4,20))
data = dict(var1=(x1,y1), var2=(x2,y2))
a = np.c_[[d for xy in data.values() for d in xy]]
a

array([[ 0.66613738, 0.39154179, 0.52399694, 0.54694366, 0.52103419,
         0.06023608, 0.03752003, 0.14947236, 0.56515257, 0.03980963,
         0.08809146, 0.27861545, 0.62107655, 0.01718959, 0.40346171,
         0.8438409 , 0.84710117, 0.49979344, 0.93686618, 0.07087815],
       [ 0.60181235, 0.1171198 , 0.40210686, 0.12248918, 0.73587718,
         0.82907553, 0.04241232, 0.82834355, 0.89439919, 0.6477373 ,
         0.88697623, 0.12711133, 0.08061116, 0.96609631, 0.69845226,
         0.32363392, 0.05150339, 0.05108155, 0.66766576, 0.93701382],
       [ 0.85075356, 0.12107294, 0.33732861, 0.22221564, 0.04249297,
         0.54150883, 0.16414129, 0.93346553, 0.52176851, 0.24449367,
         0.5526363 , 0.23359769, 0.40763005, 0.62820355, 0.70694987,
         0.51204826, 0.15503887, 0.58975501, 0.32507773, 0.76876558],
       [ 0.54390474, 0.30364361, 0.8469127 , 0.79118699, 0.88471469,
         0.98490908, 0.03890524, 0.52584869, 0.08669779, 0.42734853,
         0.17571326, 0.33677747, 0.3046382 , 0.17856421, 0.26186241,
         0.2688219 , 0.97639377, 0.85320323, 0.84821184, 0.31592768]])

···

On Fri, 13 Jun 2008, washakie apparently wrote:

washakie wrote:

DataDict={var1:(x1,y1),var2:(x2,y2),var3:(x3,y3)} ; where the x and y's are
generally lists.

You might be able to use numpy record arrays (recarray). There are lots of good reasons to use numpy arrays other than plotting.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...

Okay??

That does seem to work... I guess I'd better go read up on index_tricks.py ?

Thanks.

Alan G Isaac wrote:

···

x1,y1,x2,y2 =np.random.random((4,20))
data = dict(var1=(x1,y1), var2=(x2,y2))
a = np.c_[[d for xy in data.values() for d in xy]]
a

array([[ 0.66613738, 0.39154179, 0.52399694, 0.54694366, 0.52103419,
         0.06023608, 0.03752003, 0.14947236, 0.56515257, 0.03980963,
         0.08809146, 0.27861545, 0.62107655, 0.01718959, 0.40346171,
         0.8438409 , 0.84710117, 0.49979344, 0.93686618, 0.07087815],
       [ 0.60181235, 0.1171198 , 0.40210686, 0.12248918, 0.73587718,
         0.82907553, 0.04241232, 0.82834355, 0.89439919, 0.6477373 ,
         0.88697623, 0.12711133, 0.08061116, 0.96609631, 0.69845226,
         0.32363392, 0.05150339, 0.05108155, 0.66766576, 0.93701382],
       [ 0.85075356, 0.12107294, 0.33732861, 0.22221564, 0.04249297,
         0.54150883, 0.16414129, 0.93346553, 0.52176851, 0.24449367,
         0.5526363 , 0.23359769, 0.40763005, 0.62820355, 0.70694987,
         0.51204826, 0.15503887, 0.58975501, 0.32507773, 0.76876558],
       [ 0.54390474, 0.30364361, 0.8469127 , 0.79118699, 0.88471469,
         0.98490908, 0.03890524, 0.52584869, 0.08669779, 0.42734853,
         0.17571326, 0.33677747, 0.3046382 , 0.17856421, 0.26186241,
         0.2688219 , 0.97639377, 0.85320323, 0.84821184, 0.31592768]])

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

--
View this message in context: http://www.nabble.com/Handling-data-and-creating-arrays-tp17834278p17834620.html
Sent from the matplotlib - users mailing list archive at Nabble.com.