Pivot -- Equivalent Of Transpose() For 2D Arrays


Recommended Posts

I needed to process a 2D array column-wise, but the relevant functions only worked row-wise. So I could transpose() the array, use the row-wise functions, then transpose() it back, but transpose() only works on 1D arrays. This is an equivalent for 2D arrays:


function pivot (string source)

private string dest
for(private idx = 0, idx < NumCols(source), idx++)
dest[idx] = Transpose(source[][idx], 1)
endfor
return dest
[/CODE]

Link to comment
Share on other sites

I had to step through in order to examine each column anyway, to see which ones needed deleting, but there was only one iteration per column, so for this particular app that was about as good as it was going to get.

Oddly I did try MyNewArray[][jdx] = MyOldArray[][idx] (as well as MyNewArray[][jdx] = transpopse(MyOldArray[][idx], 1)), copying across just the columns I wanted to keep, but the assignment didn't seem to work for some reason.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.