Questions tagged [transpose]

Transposition is an operation that applies to matrices wherein the rows and columns are swapped

The transpose of a matrix A is written as A'. The transpose of matrix A is another matrix B in which the element in the ith row and the jth column of A is in the jth row and the ith column of B. For example:

Suppose A =

[[11, 12, 13],
 [21, 22, 23],
 [31, 32, 33]]

Then, A' =

[[11, 21, 31],
 [12, 22, 32],
 [13, 23, 33]]

In scientific software for statistical computing and graphics, function t transposes a matrix.

3257 questions
7
votes
1 answer

Python pandas convert rows to columns where multiple columns exist

I have a DF with multiple columns which I want to convert from rows to columns most solutions I have seen on stack overflow only deal with 2 columns From DF PO ID PO Name Region Date Price 1 AA North 07/2016 100 2 BB …
yasin mohammed
  • 461
  • 2
  • 10
  • 26
7
votes
2 answers

Fortran reshape - N-dimensional transpose

I'm trying to write some code in Fortran which requires the re-ordering of an n-dimensional array. I thought the reshape intrinsic combined with the order argument should allow this, however I'm running into difficulties. Consider the following…
7
votes
3 answers

Explain how this array transposing and flattening function works

Here this function in PHP that allows to merge any N amount of different length arrays in a fashion that output array will be in next order: Array1[0],Array2[0],..,ArrayN[0],Array1[1],Array2[1],..,ArrayN[1]... : function array_zip_merge() { …
Acidon
  • 1,294
  • 4
  • 23
  • 44
7
votes
1 answer

Need to convert columns to rows in R

I have data that looks like a b c 1 5 4 3 6 1 2 5 3 I want to convert it to convert all the columns to rows and want an output like r1 r2 r3 r4 a 1 3 2 b 5 6 5 c …
Ishan Basu
  • 181
  • 1
  • 1
  • 12
7
votes
1 answer

Lists sorting in Python (transpose)

I have arbitrary lists, for instance here are three lists: a = [1,1,1,1] b = [2,2,2,2] c = [3,3,3,3] And I want transpose them together in order to get the output like this: f_out = [1,2,3] g_out = [1,2,3] ... n_out = [1,2,3] As, you can see, I…
Vadim
  • 4,219
  • 1
  • 29
  • 44
7
votes
2 answers

How to transpose a matrix in C? - error

I am trying to write a function to transpose matrices. paramters of that function: the matrix to transpose the output matrix which is empty. The problem is I am able to transpose some matrices but some other fail like the one i am giving in my…
7
votes
1 answer

numpy einsum to get axes permutation

What I understood in the documentation of ‘np.einsum‘ is that a permutation string, would give a permutation of the axis in a vector. This is confirmed by the following experiment: >>> M = np.arange(24).reshape(2,3,4) >>> M.shape (2, 3, 4) >>>…
Emanuele Paolini
  • 9,912
  • 3
  • 38
  • 64
7
votes
5 answers

Create object from array of keys and values

I've been banging my head against the wall for several hours on this and just can't seem to find a way to do this. I have an array of keys and an array of values, how can I generate an object? Input: [["key1", "key2"], ["val1",…
Abdullah Jibaly
  • 53,220
  • 42
  • 124
  • 197
7
votes
1 answer

Matlab - Transpose a 3D matrix only in the third dimension

I have a 3 x 3 x 2 matrix, for example : M(:,:,1) = 1 2 3 4 5 6 7 8 9 M(:,:,2) = 10 11 12 13 14 15 16 17 18 and I would like to transpose each M(:,:,i), I mean I would like to…
user2370336
  • 73
  • 1
  • 5
7
votes
1 answer

Rearrange tuple of tuples in Python

I have a tuple of tuples: t = ((1, 'one'), (2, 'two')) I need it in the following format: ((1, 2), ('one', 'two')) How can I convert it? I can do something like: digits = tuple ( digit for digit, word in t ) words = tuple ( word for…
lizarisk
  • 7,562
  • 10
  • 46
  • 70
7
votes
1 answer

Which is faster, numpy transpose or flip indices?

I have a dynamic programming algorithm (modified Needleman-Wunsch) which requires the same basic calculation twice, but the calculation is done in the orthogonal direction the second time. For instance, from a given cell (i,j) in matrix scoreMatrix,…
Todd Gillette
  • 150
  • 1
  • 11
7
votes
2 answers

how to transpose a matrix in r if the usual `t( )` doesn't work?

I have a matrix I am trying to transpose in R but the t() function does not return the right answer. How can I transpose the matrix? > xx=matrix(c(3,7,4,8),2,byrow=TRUE) > xx [,1] [,2] [1,] 3 7 [2,] 4 8 > t(xx) [1] 0.7071068…
user1854786
  • 71
  • 1
  • 1
  • 2
6
votes
1 answer

Transpose of a matrix in numpy

I have this numpy array: a = np.array([[[1,2,3],[-1,-2,-3]],[[4,5,6],[-4,-5,-6]]]) b is a transpose of a. I want b be like this: b = np.array([[[1,-1],[2,-2],[3,-3]],[[4,-4],[5,-5],[6,-6]]]) Is it possible to do it in one line? EDIT: And if I…
Academia
  • 3,984
  • 6
  • 32
  • 49
6
votes
1 answer

Transpose large numpy matrix on disk

I have a rather large rectangular (>1G rows, 1K columns) Fortran-style NumPy matrix, which I want to transpose to C-style. So far, my approach has been relatively trivial with the following Rust snippet, using MMAPed slices of the source and…
Luca Cappelletti
  • 2,485
  • 20
  • 35
6
votes
4 answers

SQL to transpose row pairs to columns in MS ACCESS database

I have an MS Access database that contains translated sentences in source-target pairs (a translation memory for fellow users of CAT tools). Somewhat annoyingly, source and target are not stored in separate columns, but in rows linked by ID, like…
Marek Jedliński
  • 7,088
  • 11
  • 47
  • 57