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


Groups > comp.lang.python > #79246 > unrolled thread

Re: your mail

Started byTerry Reedy <tjreedy@udel.edu>
First post2014-10-17 12:37 -0400
Last post2014-10-18 15:03 +0200
Articles 3 — 3 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: your mail Terry Reedy <tjreedy@udel.edu> - 2014-10-17 12:37 -0400
    Re: your mail Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2014-10-18 13:15 +0200
      Re: your mail Peter Otten <__peter__@web.de> - 2014-10-18 15:03 +0200

#79246 — Re: your mail

FromTerry Reedy <tjreedy@udel.edu>
Date2014-10-17 12:37 -0400
SubjectRe: your mail
Message-ID<mailman.14947.1413563848.18130.python-list@python.org>
On 10/17/2014 6:43 AM, Cameron Simpson wrote:
> On 17Oct2014 11:45, Dhananjay <dhananjay.c.joshi@gmail.com> wrote:

>> 2.1576318858 -1.8651195165 4.2333428278
>> ...
>> (total of 200 lines)
>>
>> Columns 1,2,3 corresponds to x,y,z axis data points.

>    for line in open('flooding-psiphi.dat','r'):
>        line = line.split()
>        xs.append(float(line[0]))
>        ys.append(float(line[1]))
>        zs.append(float(line[2]))

A further refinement:
    for line in open('flooding-psiphi.dat','r'):
        x, y, z = map(float, line.split())
        xs.append(x)
        ys.append(y)
        zs.append(z)


-- 
Terry Jan Reedy

[toc] | [next] | [standalone]


#79269

FromAlain Ketterlin <alain@dpt-info.u-strasbg.fr>
Date2014-10-18 13:15 +0200
Message-ID<87ppdp39xv.fsf@dpt-info.u-strasbg.fr>
In reply to#79246
Terry Reedy <tjreedy@udel.edu> writes:

> On 10/17/2014 6:43 AM, Cameron Simpson wrote:
>> On 17Oct2014 11:45, Dhananjay <dhananjay.c.joshi@gmail.com> wrote:
>
>>> 2.1576318858 -1.8651195165 4.2333428278
>>> ...
>>> (total of 200 lines)
>>>
>>> Columns 1,2,3 corresponds to x,y,z axis data points.
>
>>    for line in open('flooding-psiphi.dat','r'):
>>        line = line.split()
>>        xs.append(float(line[0]))
>>        ys.append(float(line[1]))
>>        zs.append(float(line[2]))
>
> A further refinement:
>    for line in open('flooding-psiphi.dat','r'):
>        x, y, z = map(float, line.split())
>        xs.append(x)
>        ys.append(y)
>        zs.append(z)

Or even:

xs,ys,zs = zip(*[ map(float,line.split())
                  for line in open('flooding-psiphi.dat','r') ])

You get tuples, though. Use map(list,zip(...)) if you need lists. Easy
to update when you move to 4D data...

-- Alain.

[toc] | [prev] | [next] | [standalone]


#79271

FromPeter Otten <__peter__@web.de>
Date2014-10-18 15:03 +0200
Message-ID<mailman.14969.1413637402.18130.python-list@python.org>
In reply to#79269
Alain Ketterlin wrote:

> Terry Reedy <tjreedy@udel.edu> writes:
> 
>> On 10/17/2014 6:43 AM, Cameron Simpson wrote:
>>> On 17Oct2014 11:45, Dhananjay <dhananjay.c.joshi@gmail.com> wrote:
>>
>>>> 2.1576318858 -1.8651195165 4.2333428278
>>>> ...
>>>> (total of 200 lines)
>>>>
>>>> Columns 1,2,3 corresponds to x,y,z axis data points.
>>
>>>    for line in open('flooding-psiphi.dat','r'):
>>>        line = line.split()
>>>        xs.append(float(line[0]))
>>>        ys.append(float(line[1]))
>>>        zs.append(float(line[2]))
>>
>> A further refinement:
>>    for line in open('flooding-psiphi.dat','r'):
>>        x, y, z = map(float, line.split())
>>        xs.append(x)
>>        ys.append(y)
>>        zs.append(z)
> 
> Or even:
> 
> xs,ys,zs = zip(*[ map(float,line.split())
>                   for line in open('flooding-psiphi.dat','r') ])
> 
> You get tuples, though. Use map(list,zip(...)) if you need lists. Easy
> to update when you move to 4D data...

Given the context (the script uses numpy) there is another option:

xs, ys, zs = numpy.loadtxt('flooding-psiphi.dat').T

There may also be a way to feed the array to matplotlib without breaking it 
into the three columns...

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web