A Collection of Code Snippets in as Many Programming Languages as Possible

This project is maintained by TheRenegadeCoder

Welcome to the Transpose Matrix page! Here, you'll find a description of the project as well as a list of sample programs written in various languages.

This article was written by:

- Jeremy Grifski
- rzuckerm

In linear algebra, the transpose of a matrix is an operator which flips a matrix over its diagonal;
that is, it switches the row and column indices of the matrix A by producing another matrix, often
denoted by A^{T}. For example, the following matrix could be the matrix A:

column 1 | column 2 | column 3 | |
---|---|---|---|

row 1 | 1 | 2 | 3 |

row 2 | 4 | 5 | 6 |

row 3 | 7 | 8 | 9 |

Once transposed, A becomes the following matrix, A^{T}:

column 1 | column 2 | column 3 | |
---|---|---|---|

row 1 | 1 | 4 | 7 |

row 2 | 2 | 5 | 8 |

row 3 | 3 | 6 | 9 |

The transpose of a matrix was introduced in 1858 by the British mathematician Arthur Cayley.

For the purposes of this project, we'll ask that you create a program which accepts a matrix as a list of integers and the dimensions of that matrix in the following format:

```
transpose-matrix.lang 3 3 "1, 2, 3, 4, 5, 6, 7, 8, 9"
```

Here, the first two input numbers indicate the column and row size of the matrix, respectively, and the next input is the list of numbers to be included in the matrix.

Every project in the Sample Programs repo should be tested. In this section, we specify the set of tests specific to Transpose Matrix. In order to keep things simple, we split up the testing as follows:

- Transpose Matrix Valid Tests
- Transpose Matrix Invalid Tests

Description | Cols | Rows | Matrix | Output |
---|---|---|---|---|

Sample Input: Routine | "3" | "2" | "1, 2, 3, 4, 5, 6" | "1, 4, 2, 5, 3, 6" |

Description | Cols | Rows | Matrix |
---|---|---|---|

No Input | |||

Missing Input: No Columns Or Rows | "" | "" | "1, 2, 3, 4, 5, 6" |

Missing Input: No Matrix | "3" | "3" | "" |

All of these tests should output the following:

```
Usage: please enter the dimension of the matrix and the serialized matrix
```

- Transpose Matrix in Algol68
- Transpose Matrix in Beef
- Transpose Matrix in Commodore Basic
- Transpose Matrix in Euphoria
- Transpose Matrix in Javascript
- Transpose Matrix in Mathematica
- Transpose Matrix in Php
- Transpose Matrix in Python
- Transpose Matrix in Rust
- Transpose Matrix in Typescript