0

我有一个函数,它的输出是一系列列表[a,b,c,d] [a,b,c,d] [a,b,c,d] [a,b,c,d]

而且我要[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)

这是我的函数和程序,我将如何获取代码以读取q一个列表中的所有j' zs 和h它们自己的列表中的所有 's。我知道我可以将函数分成四个不同的函数,但这仍然不会在列表中返回我的结果,它只是单独输出它们。

4

2 回答 2

2
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)
于 2013-05-28T20:47:24.980 回答
0

你可以这样写:

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)
于 2013-05-28T21:54:48.547 回答