Skip to content

Instantly share code, notes, and snippets.

@claytonjwong
Created April 8, 2022 19:19
Show Gist options
  • Save claytonjwong/ed5617c0fcc8ddc6636312b754432cb1 to your computer and use it in GitHub Desktop.
Save claytonjwong/ed5617c0fcc8ddc6636312b754432cb1 to your computer and use it in GitHub Desktop.

Revisions

  1. claytonjwong created this gist Apr 8, 2022.
    14 changes: 14 additions & 0 deletions transpose_matrix.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    *Kotlin*
    ```
    var transpose = { A: Array<IntArray> -> A[0].mapIndexed{ j, _ -> A.mapIndexed{ i, _ -> A[i][j] }.toIntArray() }.toTypedArray() }
    ```

    *Javascript*
    ```
    let transpose = A => A[0].map((_, j) => A.map((_, i) => A[i][j]));
    ```

    *Python3*
    ```
    transpose = lambda A: [[A[i][j] for i in range(len(A))] for j in range(len(A[0]))]
    ```