Question

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.

Was it helpful?

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)

OTHER TIPS

You can write it this way:

def meanarr(image, res=None):
    "costruct 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]
    return a

data =[meanarr(arg) for arg in sys.argv[1:]]
print zip(*data)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top