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

transpose/rotate a block of a matrix in python

i have a 6x6 matrix as a list of lists in python. The matrix is divided into 4 square blocks of size 3x3. I want a way to take a transpose of only 1 block. I can do it using the traditional method of going through each element and copying it into…
randomThought
  • 6,203
  • 15
  • 56
  • 72
8
votes
2 answers

WorksheetFunction.Transpose changes data type

I was using WorksheetFunction.Transpose in VBA to convert a 1D array of mixed dates/strings into a 2D array for writing to a worksheet. With my windows regional settings set to DMY, the dates being written back were having months/day switched.
Ron Rosenfeld
  • 53,870
  • 7
  • 28
  • 60
8
votes
4 answers

Repeat each row N times in Google Sheets

I have a column containing 3 rows and I want to be able to repeat those rows 5 times each. Example Name Dog Cat Ball Desired…
Wes Foster
  • 8,770
  • 5
  • 42
  • 62
8
votes
7 answers

How to "transpose" a list of vectors?

I have a list of vectors: asdf = list(c(1, 2, 3, 4, 5), c(10, 20, 30, 40, 50)) Now I want to "transpose" it, that is, obtain a list of 5 pairs instead of a pair of lists of 5. To be more specific, I want the result to be analogous to the result of…
user4385532
8
votes
1 answer

Simple row transposition cipher

For a Lisp class, we were given a simple row transposition cipher homework, which I tried to solve in Haskell, too. Basically, one just splits a string into rows of length n, and then transposes the result. The concatenation of the resulting list of…
danlei
  • 14,121
  • 5
  • 58
  • 82
8
votes
0 answers

Proposing an algorithm for arbitrary shape Bit Matrix Transposition with BDD-like structure

We consider a bit matrix (n x m) to be a regular array containing n lines of integers of size m. I have looked in Hacker's Delight and in other sources and the algorithms I found for this were rather specialized: square matrices with powers of two…
8
votes
1 answer

Differences of transpose functions in python

I am generating a large matrix (100x100, let's call it X) with random numbers, with numpy.matrix() so that I have a numpy.ndarray. I have been wondering if there are any difference between the two operations: numpy.transpose(X) X.T I have measured…
Whir
  • 305
  • 3
  • 16
8
votes
2 answers

Optimal SIMD algorithm to rotate or transpose an array

I am working on a data structure where I have an array of 16 uint64. They are laid out like this in memory (each below representing a single int64): A0 A1 A2 A3 B0 B1 B2 B3 C0 C1 C2 C3 D0 D1 D2 D3 The desired result is to transpose the array into…
Thomas Kejser
  • 1,264
  • 1
  • 10
  • 30
8
votes
1 answer

Cache Memory Optimization Array Transpose: C

typedef int array[2][2]; void transpose(array dst, array src) { int i, j; for (j = 0; j < 2; j++) { for (i = 0; i < 2; i++) { dst[i][j] = src[j][i]; } } } src array starts at address 0 and the dst array…
8
votes
2 answers

SQL Transpose rows to columns (group by key variable)?

I am trying to transpose rows into columns, grouping by a unique identifier (CASE_ID). I have a table with this structure: CASE_ID AMOUNT TYPE 100 10 A 100 50 B 100 75 A 200 33 B …
user2895991
  • 101
  • 1
  • 1
  • 4
8
votes
2 answers

transpose a map collecting keys along the way

I'm trying to transpose a map so that: [x: y, w: y, a: b] becomes [y: [x, w], b: a] (all variables are strings) Doing something like ["x": "y", "w": "y", "a": "b"].collectEntries { [it.value, it.key] } gets me part way, but stomps on the first…
Scott Presnell
  • 1,528
  • 10
  • 23
7
votes
2 answers

Transpose a 1 dimensional array, that does not represent a square, in place

This question is similar to this, but instead of an array that represents a square, I need to transpose a rectangular array. So, given a width: x and a height: y, my array has x*y elements. If width is 4 and height is 3, and I…
Julian Mann
  • 6,256
  • 5
  • 31
  • 43
7
votes
6 answers

How to convert vertical pandas table of 2 columns to horizontal table based on common ID value in python

df1 = pd.DataFrame({'foo': ['one', 'one', 'one', 'two', 'two', 'two'], 'bar': ['A', 'B', 'C', 'A', 'B', 'C']}) foo bar 0 one A 1 one B 2 one C 3 two A 4 two B 5 two C I would like to convert this…
7
votes
5 answers

How to average columns of data from multiple, flat arrays?

Let's say I have 4 arrays with the same amount of values in each: $array1 = array(0, 7, 5, 0); $array2 = array(2, 6, 10, 0); $array3 = array(4, 8, 15, 10); $array4 = array(6, 7, 20, 10); I want to count the average for all 4 of these arrays for…
KarelRuzicka
  • 461
  • 2
  • 13
7
votes
4 answers

Is there a python builtin to create tuples from multiple lists?

Is there a python builtin that does the same as tupler for a set of lists, or something similar: def tupler(arg1, *args): length = min([len(arg1)]+[len(x) for x in args]) out = [] for i in range(length): out.append(tuple([x[i]…
Lucas
  • 1,869
  • 4
  • 20
  • 36