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
34
votes
4 answers

Numpy transpose of 1D array not giving expected result

I am trying a very basic example in Python scipy module for transpose() method but it's not giving expected result. I am using Ipython with pylab mode. a = array([1,2,3] print a.shape >> (3,) b = a.transpose() print b.shape >> (3,) If I print the…
sarbjit
  • 3,786
  • 9
  • 38
  • 60
33
votes
2 answers

How to transpose a dataframe in tidyverse?

Using basic R, I can transpose a dataframe, say mtcars, which has all columns of the same class: as.data.frame(t(mtcars)) Or with pipes: library(magrittr) mtcars %>% t %>% as.data.frame How to accomplish the same within tidyr or tidyverse…
Irakli
  • 959
  • 1
  • 11
  • 18
30
votes
9 answers

Transpose / reshape dataframe without "timevar" from long to wide format

I have a data frame that follows the below long Pattern: Name MedName Name1 atenolol 25mg Name1 aspirin 81mg Name1 sildenafil 100mg Name2 atenolol 50mg Name2 enalapril 20mg And would like to get below (I do not…
Hotamd6
  • 315
  • 3
  • 8
29
votes
3 answers

How do I transpose a tibble() in R

In R the t() function is really meant for matrices. When I try to transpose my tibble with t() I end up with a matrix. A matrix can't be made into a tibble with tibble(). I end up spending time storing column names as variables and attaching them as…
Alex
  • 2,603
  • 4
  • 40
  • 73
29
votes
3 answers

Convert column to row in Python Pandas

I have the following Python pandas dataframe: fruits | numFruits --------------------- 0 | apples | 10 1 | grapes | 20 2 | figs | 15 I want: apples | grapes | figs ----------------------------------------- Market 1…
Reise45
  • 1,163
  • 4
  • 18
  • 23
28
votes
5 answers

Transposing in dplyr

I have the following data.frame df = structure(list(HEADER = c("HOME_TRPM", "AWAY_TRPM", "HOME_TEAM","AWAY_TEAM"), price = c("0.863104076023855", "-0.845186446996287","CHA", "NOP")), .Names = c("HEADER", "price"),…
geodex
  • 1,219
  • 3
  • 13
  • 22
28
votes
2 answers

Converting rows into columns and columns into rows using R

I have a dataframe with unique row names and unique column names. I want to convert the rows into columns and column into rows. For example, this code: starting_df <- data.frame(row.names= c(LETTERS[1:4]), a = c(1:4), …
Christopher Bottoms
  • 11,218
  • 8
  • 50
  • 99
26
votes
7 answers

How to transpose a dataset in a csv file?

For example, i would like to transform: Name,Time,Score Dan,68,20 Suse,42,40 Tracy,50,38 Into: Name,Dan,Suse,Tracy Time,68,42,50 Score,20,40,38 Edit: The original question used the term "transpose" incorrectly.
zr.
  • 7,528
  • 11
  • 50
  • 84
23
votes
7 answers

What is the best way to transpose a data.frame in R and to set one of the columns to be the header for the new transposed table?

What is the best way to transpose a data.frame in R and to set one of the columns to be the header for the new transposed table? I have coded up a way to do this below. As I am still new to R. I would like suggestions to improve my code as well as…
themartinmcfly
  • 2,004
  • 2
  • 13
  • 12
23
votes
2 answers

Transpose array and actually reorder memory

I have a 3-D NumPy array, e.g. a = np.random.random((2,3,5)) I would like to transpose the last two axes, i.e. b = a.transpose(0,2,1) However, I do not want a view with twiddled strides! I want to actually copy the array and reorder it in memory.…
bdforbes
  • 1,486
  • 1
  • 13
  • 31
22
votes
3 answers

Excel VBA - Range.Copy transpose paste

I am following the help menu for PasteSpecial but I cannot seem to get my code to work without an error. I want to take Worksheets("Sheet1").Range("A1","A5") and paste transpose to Worksheets("Sheet2").Range("A1","E1"). What is the most simple way…
user1130306
  • 519
  • 3
  • 7
  • 11
22
votes
12 answers

Multi-dimensional array transposing

I have a row-based multidimensional array: /** [row][column]. */ public int[][] tiles; I would like to transform this array to column-based array, like following: /** [column][row]. */ public int[][] tiles; ...But I really don't know where to…
Antti Kolehmainen
  • 1,071
  • 1
  • 11
  • 23
22
votes
4 answers

Transpose DataFrame Without Aggregation in Spark with scala

I looked number different solutions online, but count not find what I am trying to achine. Please help me on this. I am using Apache Spark 2.1.0 with Scala. Below is my dataframe: +-----------+-------+ |COLUMN_NAME| VALUE…
Maruti K
  • 233
  • 1
  • 2
  • 7
21
votes
2 answers

How to permutate tranposition in tensorflow?

From the docs: Transposes a. Permutes the dimensions according to perm. The returned tensor's dimension i will correspond to the input dimension perm[i]. If perm is not given, it is set to (n-1...0), where n is the rank of the input tensor.…
alvas
  • 115,346
  • 109
  • 446
  • 738
20
votes
2 answers

Transpose Pandas DataFrame and change the column headers to a list

I have the following Pandas sub-dataframe col1 name1 name2 522 a 10 0.2 1021 b 72 -0.1 col1 has no duplicate. I want to transpose the dataframe and change the column header to col1 values. Ideally the output…
Hamed
  • 757
  • 3
  • 10
  • 17