Languages

Java transpose matrix

3 points
Asked by:
Root-ssh
178290

How to transpose matrix in java?

I have:

And I expect:

 

1 answer
3 points
Answered by:
Root-ssh
178290

Quick solution (it works for square and rectangular matrixes) :

Example 1

Below example transpose square matrix of size 3 x 3 (3 rows, 3 columns), with total 9 elements. Transposition logic is the same as in quick solution above.

Output:

Example 2

Below example transpose rectangular matrix of size 2 x 4 (2 rows, 4 columns), with total 8 elements. Transposition logic is the same. We only change the input matrix.

Output:

Some details

In math, transpose of matrix is the process of chaning rows to columns and columns to rows. The process of transposition is quite easy, we just change A[i][j] to A[j][i].
We can do it in couple of different ways.
It is very oftne used in linear algebra.

Wikipedia has quite solid articles about this topic.

0 commentsAdd comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join