# How can I transpose a matrix A using tmp

I have the following MWE:

\documentclass[tikz,border=5mm]{standalone}
\usepackage{etoolbox}
\usetikzlibrary{fixedpointarithmetic}
\usetikzlibrary{math}
\usepackage{siunitx}

\tikzmath{
\n=6;
int \i;
for \i in {0,...,\n}{
\x{\i} = \i;
\y{\i} = sin(\i r);
\z{\i} = cos(\i r);
};
}

\begin{document}

\pgfkeys{/pgf/number format/.cd,fixed,precision=4,zerofill}%
\edef\k{0}%
\loop
\xappto\tmp{$\k$ & $\x{\k}$&  $\y{\k}$ & $\z{\k}$ }%
\edef\k{\the\numexpr\k+1}%
\gappto\tmp{\\}%
\ifnum\k<\fpeval{\n+1}\repeat

Consider the matrix:\\

$A = \left[ \begin{array}{cccccc} \tmp \end{array} \right]$\\

How can I write the transpose of $A$? A code for:\\

$A = \left[ \begin{array}{ccccccc} 0& 1 & 2 & 3 & 4 &5 & 6\\ \ldots&\\ \end{array} \right]$\\

\end{document}

whose output is the following:

Then I define \n and build the values of x and y using tikzmath . Then, I use the code

\pgfkeys{/pgf/number format/.cd,fixed,precision=4,zerofill}%
\edef\k{0}%
\loop
\xappto\tmp{$\k$ & $\x{\k}$&  $\y{\k}$ & $\z{\k}$ }%
\edef\k{\the\numexpr\k+1}%
\gappto\tmp{\\}%
\ifnum\k<\fpeval{\n+1}\repeat

to build the matrix iteratively line per line. Woks very well.

However, if I want to build the matrix per columns using this resource (not manually), e.g, how can I build the transpose of this matrix using \tmp environment? Is there a way to transpose these matrix?

• pgfplotstable can generate a transpose, if it is already in pgfplotstable format. You might also look into using \csname arrays instead of pgfmath arrays. See tex.stackexchange.com/questions/346260/… for example. Commented Aug 1 at 15:46