Name:Rebin
Category:IDL
Author:Conor
Tip:

Rebin is the second part of the powerful reform/rebin combination.  Rebin is used to resize arrays.  It can shrink or expand them according to your needs.  When shrinking arrays, it essentially averages elements to make your new array.  When expanding, it extrapolates between points.  You use rebin by passing it the array to modify, and the new dimensions to change it to.  When expanding, the new dimensions have to be integer factors of the original dimensions (i.e. a 2x2 array would have to be 4x4, 2x4, 4x2, 6x2, etc...).  The same goes for shrinking arrays (i.e a 4x4 array could be shrunk to 4x2, 2x4, 2x2, 4x1, 1x4, and 1x1 only).

 IDL> test = findgen(10)
IDL> print,rebin(test,5)
     0.500000      2.50000      4.50000      6.50000      8.50000
IDL> print,rebin(test,20)
      0.00000     0.500000      1.00000      1.50000      2.00000      2.50000      3.00000      3.50000      4.00000      4.50000      5.00000      5.50000      6.00000      6.50000      7.00000
      7.50000      8.00000      8.50000      9.00000      9.00000

Rebin is also very handy for averaging along rows or columns.  For instance, if you have a large array and you want to know the average of every row individually, you would do this:

IDL> test = findgen(2,4)
IDL> print,test
      0.00000      1.00000
      2.00000      3.00000
      4.00000      5.00000
      6.00000      7.00000
IDL> print,rebin(test,1,4)
     0.500000
      2.50000
      4.50000
      6.50000