transpose array
Steven D'Aprano
steven at REMOVE.THIS.cybersource.com.au
Tue Oct 27 20:28:00 EDT 2009
On Tue, 27 Oct 2009 15:26:55 -0700, 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
> ...
f = open('myfile.txt', 'w')
for t in zip(xVec, yVec, zVec):
f.write('%s, %s, %s\n' % t)
f.close()
If the lists are really huge, you should use itertools.izip() instead of
zip().
--
Steven
More information about the Python-list
mailing list