transpose array
hello everyone
i have 3 arrays
xVec=[a1,a2,a3,a4,a5]
yVec=[b1.b2.b3.b4.b5]
zVec=[c1,c2,c3,c4,c5]
and i want to output them to a ascii file like so
a1,b1,c1
a2,b2,c2
a3,b3,c3
...
now i'm using
print >>f, str(xVec).replace('[',' ').replace(']', ' ')
print >>f, str(yVec).replace('[',' ').replace(']', ' ')
print >>f, str(zVec).replace('[',' ').replace(']', ' ')
which dumps them like
a1,a2,a3,a4,a5
b1.b2.b3.b4.b5
c1,c2,c3,c4,c5
--
http://mail.python.org/mailman/listinfo/python-list
Re: transpose array
On Oct 28, 4:48 am, alex23 wrote:
> On Oct 28, 8:26 am, yoshco wrote:
>
> > hello everyone
> > i have 3 arrays
> > xVec=[a1,a2,a3,a4,a5]
> > yVec=[b1.b2.b3.b4.b5]
> > zVec=[c1,c2,c3,c4,c5]
>
> > and i want to output them to a ascii file like so
>
> > a1,b1,c1
> > a2,b2,c2
> > a3,b3,c3
> > ...
>
> I'd probably go with something like the following:
>
> all_arrays = zip(xVec, yVec, zVec)
> formatter = lambda t: '%s\n' % ', '.join(map(str, t))
> with open('transpose.txt', 'w') as out:
> out.writelines(formatter(t) for t in all_arrays)
>
> Hope this helps.
thanks to you all
--
http://mail.python.org/mailman/listinfo/python-list
