transpose array

Edward A. Falk falk at green.rahul.net
Wed Oct 28 00:09:11 CET 2009


In article <cd144a8c-5038-45af-bc1c-509be4702903 at l13g2000yqb.googlegroups.com>,
yoshco  <yes.she at gmail.com> 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
>...

Elegant or obfuscated, you be the judge:

  vv = [xVec, yVec, zVec]

  for i in range(len(xVec)):
    print >>f,  ", ".join([x[i] for x in vv])


To be honest, I'd be more likely to do it like this, for readability if
for no other reason:

  for i in range(len(xVec)):
    print >>f, "%f, %f, %f" % (xVec[i], yVec[i], zVec[i])



It might help if we knew what you're *really* trying to do.

-- 
	-Ed Falk, falk at despams.r.us.com
	http://thespamdiaries.blogspot.com/



More information about the Python-list mailing list