transpose array

Ishwor Gurung ishwor.gurung at gmail.com
Wed Oct 28 00:13:29 CET 2009


Hi,

>> 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
>
>>>> xVec=[a1,a2,a3,a4,a5]
>>>> yVec=[b1,b2,b3,b4,b5]
>>>> zVec=[c1,c2,c3,c4,c5]
>>>> import sys, csv
>>>> from itertools import izip
>>>> csv.writer(sys.stdout).writerows(izip(xVec, yVec, zVec))
> a1,b1,c1
> a2,b2,c2
> a3,b3,c3
> a4,b4,c4
> a5,b5,c5

Or, http://docs.scipy.org/doc/numpy/reference/generated/numpy.transpose.html :-)
-- 
Regards,
Ishwor Gurung



More information about the Python-list mailing list