El jue, 25-09-2008 a las 22:19 +0200, Oz Nahum escribió: > >¿What's the meaning of that data arrange? I can't make any sense of > >plotting a 2D scatter from a 3D array. > > when I wrote: > head = [[0, 0, 10], > [1, 0, 13], > [2, 0, 11], > [3, 0, 12], > [1, 2, 11]] > > my meaning was to represent point of intereset with x, y coordinates > and the 3rd number was height for example. > I felt like I couldn't access the individual points easily, because > their are located in on big list... > So I wanted to have the list broken into rows, and the each row > represents a value on the y axis... like this: > head = [ > [[0, 0, 10], [0, 0, 13]], > [[2, 0, 11], [3, 0, 12]], > ]
Mm... maybe this is better for your eyes but not for processing, I think. > > But that's redundant I think now, after looking into the function > zip. > Maybe I could write head in the following way: > > # j = 0 1 > head = [ > [[ 0, 10], [ 1, 13]], # i =0 > [[ 0, 11], [ 1, 12]], # i =1 > ] The same. Parsing a data file usually yields a sequence of rows (records), data processing functions usually expects columns of homogeneous data and convert from records to columns and back is pretty straightforward using zip. If you want to use a different representation for your data you'll need to handle more complex structures and conversions. Do it if you think it pays (sometimes it does). > But actually after understanding what zip does, I think I don't need > it anyway... > Talking about this: can you give me an example of another use of zip ? > not just zip(*head) > > I did help(zip) but I could partially understand what it does. I > learned more by doing: > x,y,z = zip(*head) > and then printing x,y,z individually. There is no other use I can think of. If you think of the arguments passed to zip as rows, it returns the columns. If the arguments are columns, zip returns rows. How you name things depends on how you think of your data. There is no other use I can think of. zip expects each row (if they are rows) to be passed as an argument so you usually need that * thing to unpack them. When you call zip(*x), x being a sequence or array-like, you are actually passing each element of x as an argument to zip. Try this: numbers = [1, 2, 3, 4, 5] english = ['one', 'two', 'three', 'four', 'five'] spanish = ['uno', 'dos', 'tres', 'cuatro', 'cinco'] x = [numbers, english, spanish] zip(numbers, english, spanish) zip(x) zip(*x) You can learn about unpacking and zipping sequences reading the Python Tutorial or another similar resource (maybe Dive into Python dives into it, not sure but a useful reading anyway). Goyo ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users