transpose

Need to convert columns to rows in R

走远了吗. 提交于 2019-12-04 07:46:36
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 4 1 3 Thanks in advance We can transpose the dataset and convert to data.frame with the first column as the row names. m1 <- t(df1) d2 <- data.frame(r1= row.names(m1), m1, row.names=NULL) EDIT: Included the row.names argument in the data.frame call (from @Richard Scriven's comment) Or as @Ananda Mahto mentioned, we can use names(df1) to create the 'r1' column, thereby skipping the creation of an object in the global environment. d2 <-

Why is complex conjugate transpose the default in Matlab

送分小仙女□ 提交于 2019-12-04 07:18:00
if A matrix has complex element and I want to transpose A to A' using the command >>A' Why it is design that a+bi be transformed into a-bi ? What it use for? From here : for complex matrices, it is almost always the case that the combined operation of taking the transpose and complex conjugate arises in physical or computation contexts and virtually never the transpose in isolation ( Strang 1988 , pp. 220-221). In matlab if you want to transpose without conjugating use .' . Actually I'd argue that there are deep reasons why the transpose IS the conjugate . Consider a matrix representation of

How to I invert a 2d list in python [duplicate]

偶尔善良 提交于 2019-12-04 06:38:52
This question already has an answer here: Transpose list of lists 10 answers I have a 2d list like this: 1 2 3 4 5 6 and I want to make this: 1 4 2 5 3 6 I've tried to do a for loop and switch each value but I keep getting an index out of bound error. Here's what I have: for i in results: for j in range(numCenturies): rotated[i][j] = results [j][i] aga From python documentation on zip function: This function returns a list of tuples, where the i-th tuple contains the i-th element from each of the argument sequences or iterables. The returned list is truncated in length to the length of the

Transpose array of TDs into Columns jQuery

故事扮演 提交于 2019-12-04 05:12:24
问题 Please help me put the cells with a class that corresponds to the column header, in the appropriate column. The iteration should be done per column and then loop through the table.temp TD array and replace the first empty cell found with the first temp td found. The end result should look similar to the table found here. var $tempScanner = $('table.temp tr td'); var tempArry = []; $tempScanner.each(function() { tempArry.push($(this)); }); tempArry = tempArry.sort(); td, th { border: 1px solid

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

你离开我真会死。 提交于 2019-12-04 05:10:06
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 0.7071068 Josh O'Brien This answer is incorrect, but in ways that were enlightening to me and might be to others, so I'll leave it up. As @mnel noted, the base R function t() must be masked by another function of the same name. Try removing the function t() and doing t(xx) again. I guarantee you'll get the correct results. What do you get when you run this: rm(t) t(xx) If

Transforming a list to a column vector in Python

大城市里の小女人 提交于 2019-12-04 04:35:16
问题 I was wondering if there's a function that takes a list X as input and outputs a column vector corresponding to X ? (I looked around and I suspect it might be: np.matrix(X).T ) 回答1: I don't think there is a function, but there is a dedicated object, np.c_ >>> X = list('hello world') >>> X ['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'] np.c_[X] array([['h'], ['e'], ['l'], ['l'], ['o'], [' '], ['w'], ['o'], ['r'], ['l'], ['d']], dtype='<U1') You can also do (note the extra square

SAS Safe Column Names

一世执手 提交于 2019-12-04 03:55:16
问题 Is there a simple way in SAS to convert a string to a SAS-safe name that would be used as a column name? ie. Rob Penridge ----> Rob_Penridge $*@'Blah@* ----> ____Blah__ I'm using a proc transpose and then want to work with the renamed columns after the transpose. 回答1: proc transpose will take those names without any modification, as long as you set options validvarname=any; If you want to work with the columns afterwards, you can use the NLITERAL function to construct named literals that can

How to transpose a 3D matrix?

ⅰ亾dé卋堺 提交于 2019-12-04 03:17:50
I have a 3D matrix x_test of size (100, 33, 66) and I want to change its dimensions to (100, 66, 33) . What is the most efficient way to do this using python3.5? I look for something along those lines: y = x_test.transpose() You can pass the desired dimensions to the function np.transpose using in your case np.transpose(x_test, (0, 2, 1)) . For example, import numpy as np x_test = np.arange(30).reshape(3, 2, 5) print(x_test) print(x_test.shape) This will print [[[ 0 1 2 3 4] [ 5 6 7 8 9]] [[10 11 12 13 14] [15 16 17 18 19]] [[20 21 22 23 24] [25 26 27 28 29]]] (3, 2, 5) Now, you can transpose

How to transpose matrix?

半腔热情 提交于 2019-12-04 00:51:59
问题 I have made 8x8 matrix using c#, and now I need to transpose the matrix. Can you help me to transpose the matrix? This is my matrix public double[,] MatriksT(int blok) { double[,] matrixT = new double[blok, blok]; for (int j = 0; j < blok ; j++) { matrixT[0, j] = Math.Sqrt(1 / (double)blok); } for (int i = 1; i < blok; i++) { for (int j = 0; j < blok; j++) { matrixT[i, j] = Math.Sqrt(2 / (double)blok) * Math.Cos(((2 * j + 1) * i * Math.PI) / 2 * blok); } } return matrixT; } 回答1: public double

__m256d TRANSPOSE4 Equivalent?

心已入冬 提交于 2019-12-03 20:14:55
Intel has included __MM_TRANPOSE4_PS to transpose a 4x4 matrix of vectors. I'm wanting to do the equivalent with __m256d. However, I can't seem to figure out how to get _mm256_shuffle_pd in the same manner. _MM_TRANSPOSE4_PS Code #define _MM_TRANSPOSE4_PS(row0, row1, row2, row3) { \ __m128 tmp3, tmp2, tmp1, tmp0; \ \ tmp0 = _mm_shuffle_ps((row0), (row1), 0x44); \ tmp2 = _mm_shuffle_ps((row0), (row1), 0xEE); \ tmp1 = _mm_shuffle_ps((row2), (row3), 0x44); \ tmp3 = _mm_shuffle_ps((row2), (row3), 0xEE); \ \ (row0) = _mm_shuffle_ps(tmp0, tmp1, 0x88); \ (row1) = _mm_shuffle_ps(tmp0, tmp1, 0xDD); \