Name:Reform
Category:IDL
Author:Conor
Tip:

Reform, in combination with rebin, is a highly useful command for array manipulation. Reform is used to "mold" arrays into new shapes. At the most basic, it can be used to quickly change row arrays into column arrays, and vice versa:

IDL> row = fltarr(15)
IDL> col = reform(row,1,15)
IDL> cube = reform(row,1,1,15)
IDL> help,row
ROW FLOAT = Array[15]
IDL> help,col
COL FLOAT = Array[1, 15]
IDL> help,cube
CUBE FLOAT = Array[1, 1, 15]

IDL> example = findgen(5,2)
IDL> print,example
0.00000 1.00000 2.00000 3.00000 4.00000
5.00000 6.00000 7.00000 8.00000 9.00000
IDL> print,reform(example,2,5)
0.00000 1.00000
2.00000 3.00000
4.00000 5.00000
6.00000 7.00000
8.00000 9.00000

Reform works by taking the array you specify (of any dimensions) and fitting it into the array dimensions you specify one element at a time. The one requirement for reform is that the starting arrays and the ending arrays have the same number of elements.