0

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.

Tonechas
  • 11,520
  • 14
  • 37
  • 68
astrochris
  • 1,546
  • 5
  • 18
  • 35

2 Answers2

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)
dugres
  • 10,969
  • 7
  • 42
  • 48
  • yes I am looking for zip, but when i run my code my data which is out putted is in the form [a,b,c,d] [a,b,c,d] [a,b,c,d] but they are not all in a list together how would i merge them into a list? for example how would i make the outputted data into the form [['a','b','c','d'], ['a','b','c','d'], ['a','b','c','d'], ['a','b','c','d']] – astrochris May 28 '13 at 20:54
  • should I save my data into a text file and then read it in to another program and use zip form there? – astrochris May 28 '13 at 20:57
  • 1
    @user2201043 : if the parts are not in a list then put them in one... like data = [part1, part2, ...] or pass the parts to zip, like zip(part1, part2, ...). – dugres May 28 '13 at 21:32
0

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)
Dan
  • 45,062
  • 13
  • 59
  • 80
cloudaice
  • 1
  • 1