Jump to content

Trying to bin one column and sum the other simultaneously. Please help.

- - - - -

  • Please log in to reply
No replies to this topic

#1
arick1234

arick1234

    Newbie

  • Members
  • Pip
  • 1 posts
I have an array [x,y] where the values of x is ascending and the y values are random. I would like to sum all of the y values together when the x values are within a certain range. I can't show you any code as i dont even know where to start with this but this is the desired effect:-

Example data:-

(1, 0.5)
(2, 5.0)
(4, 2.0)
(7, 0.5)
(8, 0.5)
(10, 2.5)
(11, 1.5)
(15, 3.0)
(18, 4.0)
(20, 0.5)
...... etc.

If the range of y is 10. So from y=1 to y=10 and from y=11 to y=20 the x values will be summed within these two bands, I will get a list:-

11.0, 9.0, ...... etc.

So far I have been advised to sum all the y values, this gives:-


import numpy, scipy, matplotlib.pylab as plt

 

mjd1, flux1, error1 = numpy.loadtxt("log_207_band1.dat", usecols=(1,2,3), unpack=True)

 

x=mjd1

y=flux1

z=zip(x,y)

 

print sum(i[1] for i in z)


I'm really at a loss of what to do next.

Thanks.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users