transpose
arrayTransposes a 2D array (swaps rows and columns)
Syntax
transpose(array) Parameters
array (array) A 2D array to transpose
Returns
array A new 2D array with rows and columns swapped
Examples
Input:
[[1, 2], [3, 4]] | transpose Output:
[[1, 3], [2, 4]] Input:
[[1, 2, 3], [4, 5, 6]] | transpose Output:
[[1, 4], [2, 5], [3, 6]] The transpose() function swaps the rows and columns of a 2D array, effectively rotating the data structure by 90 degrees.
Usage
This function is useful for reformatting tabular data, pivoting data structures, or converting between row-oriented and column-oriented representations.