pythonlistnumpyoutputpyfits

writing a range output lists into a text file or four array


I have a function and its output is a selection of lists [a,b,c,d] [a,b,c,d] [a,b,c,d] [a,b,c,d]

and I want [a,a,a,a] [b,b,b,b] [c,c,c,c] [d,d,d,d]

def meanarr(image, res=None):
    "construct code which runs over a single ccd to get the means"
    a = pyfits.getdata(image).MAG_AUTO
    q = numpy.mean(a)
    s = pyfits.getdata(image).X2WIN_IMAGE
    j = numpy.mean(s)
    f = pyfits.getdata(image).Y2WIN_IMAGE
    z = numpy.mean(f)
    g = pyfits.getdata(image).XYWIN_IMAGE
    h = abs(numpy.mean(g))
    a = [q, j, z, h]
    print a
    s0 = ''
    return res

for arg in sys.argv[1:]:
    #print arg
    s = meanarr(arg)

This is my function and program how would I get the code to read all of the q's in one list all of the j's z's and h's in their own lists. I know I could separate the function into four different functions but this still doesn't return my results in a list it just outputs them individually.


Solution

  • You might be looking for zip. Try that :  
    
    data = [['a','b','c','d'], ['a','b','c','d'], ['a','b','c','d'], ['a','b','c','d']]
    
    print data
    print zip(*data)