add transposeArray2D helper function

Committing directly without PR because I need to use it in another package. Feel free to suggest alternate name and/or implementation.