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
20
votes
3 answers

How to remove the extra row (or column) after transpose() in Pandas

After using transpose on a dataframe there is always an extra row as a remainder from the initial dataframe's index for example: import pandas as pd df = pd.DataFrame({'fruit':['apple','banana'],'number':[3,5]}) df fruit number 0 apple …
Helena K
  • 469
  • 2
  • 6
  • 15
19
votes
2 answers

How to switch columns rows in a pandas dataframe

I have the following dataframe: 0 1 0 enrichment_site value 1 last_updated value 2 image_names value 3 shipping_weight value 4 …
Blue Moon
  • 4,421
  • 20
  • 52
  • 91
18
votes
4 answers

Visual studio CTRL+SHIFT+T transpose - what does it do?

I wrote some code and tried the Ctrl + T to check transpose feature in visual studio. Just to check if CTRL + Shift + T does the reverse for this Transpose... I tried pressing Ctrl + Shift + T. and it just messed up everything... Can anyone tell me…
Umer
  • 1,891
  • 5
  • 31
  • 43
18
votes
3 answers

Split lines on spaces in Sublime Text

How can i split lines in Sublime Text 3? I tried ctrl+t, ctrl+x but it does not work. I have line such as this is a sentence i would like to make it this is a sentence
Imi
  • 529
  • 2
  • 8
  • 23
17
votes
2 answers

Pivot multiple columns based on one column in SQL Server

I have the following source and destination tables in SQL Server 2008R2. How can I do pivot(s) in TSQL to transform SourceTbl into DestTbl? Hoping that the empIndex will somehow help in the pivot. SourceTbl empId empIndex empState empStDate…
BJ Rocking
  • 173
  • 1
  • 1
  • 4
16
votes
7 answers

Rotate - Transposing a List> using LINQ C#

I'm having a List>, which is return from the remote data source (i.e., WCF). So, I need to modify the following data into a user-friendly list using LINQ The C# Code is List> PersonInfo = new List>() { new…
B.Balamanigandan
  • 4,713
  • 11
  • 68
  • 130
16
votes
1 answer

Why does the transpose function change numeric to character in R?

I've constructed a simple matrix in Excel with some character values and some numeric values (Screenshot of data as set up in Excel). I read it into R using the openxlsx package like so: library(openxlsx) data <-…
Morten Nielsen
  • 325
  • 2
  • 4
  • 19
16
votes
4 answers

Flip (transpose) the rows and columns of a 2D array without changing the number of columns

Normally, I'd be asking how to turn a 4-rowed, 3-columned array like this: 1 2 3 4 5 6 7 8 9 10 11 12 Into a 3-rowed, 4-columned array like: (I DON'T WANT THIS) 1 4 7 10 2 5 8 11 3 6 9 …
Gnuffo1
  • 3,478
  • 11
  • 39
  • 53
16
votes
5 answers

SQL Server 2008 Vertical data to Horizontal

I apologize for submitting another question on this topic, but I've read through many of the answers on this and I can't seem to get it to work for me. I have three tables I need to join and pull info on. One of the tables is only 3 columns and…
Fill in the Blank
  • 173
  • 1
  • 1
  • 4
15
votes
2 answers

Dataframe transpose with pyspark in Apache Spark

I have a dataframe df that have following structure: +-----+-----+-----+-------+ | s |col_1|col_2|col_...| +-----+-----+-----+-------+ | f1 | 0.0| 0.6| ... | | f2 | 0.6| 0.7| ... | | f3 | 0.5| 0.9| ... | | ...| ...| ...| ... …
Mehdi Ben Hamida
  • 893
  • 4
  • 16
  • 38
15
votes
4 answers

What is the best way to perform an anti-transpose in python?

Lets say I have an array a = np.arange(16).reshape((4,4)) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 But I want 15 11 7 3 14 10 6 2 13 9 5 1 12 8 4 0 which is a flip across the secondary diagonal, or a kind of…
Jaden Travnik
  • 1,107
  • 13
  • 27
15
votes
2 answers

Transposing identical objects

I got a weird result today. To replicate it, consider the following data frames: x <- data.frame(x=1:3, y=11:13) y <- x[1:3, 1:2] They are supposed to be and actually are identical: identical(x,y) # [1] TRUE Applying t() to indentical objects…
antonio
  • 10,629
  • 13
  • 68
  • 136
15
votes
4 answers

Pandas setting multi-index on rows, then transposing to columns

If I have a simple dataframe: print(a) one two three 0 A 1 a 1 A 2 b 2 B 1 c 3 B 2 d 4 C 1 e 5 C 2 f I can easily create a multi-index on the rows by issuing: a.set_index(['one', 'two']) …
sheridp
  • 1,386
  • 1
  • 11
  • 24
14
votes
1 answer

Excel: Formulas for converting data among column / row / matrix

Are there formulas to convert data in a column to a matrix or to a row? And to convert from/to other combinations? What about an even more complex case: reshape a matrix of width W to width N*W? There are a few similar or related questions. I have…
13
votes
1 answer

How to transpose matrix using uBLAS?

I am a newbie in C++ Boost uBLAS library so I have a noob question - how to transpose a matrix using this library? I could not find question here: http://www.boost.org/doc/libs/1_44_0/libs/numeric/ublas/doc/html/index.html
user306080
  • 1,409
  • 3
  • 16
  • 37