transpose

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

坚强是说给别人听的谎言 提交于 2019-12-01 02:29:18
问题 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 have : M(:,:,1) = 1 4 7 2 5 8 3 6 9 M(:,:,2) = 10 13 16 11 14 17 12 15 18 How is it possible to do this without loops ? Thank you very much ! 回答1: That's what permute does: result = permute(M, [2 1 3]); %// swap dimensions 1 and 2 来源: https://stackoverflow.com/questions/27301188/matlab-transpose-a-3d-matrix-only-in-the

Transposing a matrix from a 2D array

时光毁灭记忆、已成空白 提交于 2019-12-01 00:56:15
I'm self teaching myself some java and I'm stuck on creating a 2D array that initializes it with random values and then creates the transpose of the array. An example output is: $ java Test1 22 333 44 555 6 Enter the number of rows (1-10): 0 ERROR: number not in specified range (1-10) ! and so on until you enter the correct number of rows and columns. Original matrix 1 22 333 44 555 6 Transposed matrix 1 333 555` 22 44 6` ^ Should be the final output. Some help with the code would appreciated! I would like to code to generate error messages if the number of rows or columns is outside the

Transposing a table in SQL server

若如初见. 提交于 2019-12-01 00:38:26
I am using SQL Server 2005 for my application. I have a table in my stored procedure which has two columns, C1 and C2. I want to transpose this table such that the values of column C1 becomes the columns. Before transpose (Table 1): C1 C2 M1 U1 M1 U2 M1 U3 M2 U4 M2 U5 After Transpose (Table 2): M1 M2 U1 U4 U2 U5 U3 NULL In Table1, the number of distinct values (M1, M2) may vary. So, the columns in Table2 are not fix. Please provide a solution to achieve the same. For this type of data transformation you will want to use the PIVOT function that is available in SQL Server 2005+. There are two

How do you transpose a dask dataframe (convert columns to rows) to approach tidy data principles

六月ゝ 毕业季﹏ 提交于 2019-12-01 00:32:34
TLDR : I created a dask dataframe from a dask bag. The dask dataframe treats every observation (event) as a column. So, instead of having rows of data for each event, I have a column for each event. The goal is to transpose the columns to rows in the same way that pandas can transpose a dataframe using df.T. Details : I have sample twitter data from my timeline here . To get to my starting point, here is the code to read a json from disk into a dask.bag and then convert that into a dask.dataframe import dask.bag as db import dask.dataframe as dd import json b = db.read_text('./sampleTwitter

How to transpose data in powershell

你说的曾经没有我的故事 提交于 2019-11-30 20:53:19
问题 I have a file that looks like this: a,1 b,2 c,3 a,4 b,5 c,6 (...repeat 1,000s of lines) How can I transpose it into this? a,b,c 1,2,3 4,5,6 Thanks 回答1: Here's a brute-force one-liner from hell that will do it: PS> Get-Content foo.txt | Foreach -Begin {$names=@();$values=@();$hdr=$false;$OFS=','; function output { if (!$hdr) {"$names"; $global:hdr=$true} "$values"; $global:names=@();$global:values=@()}} -Process {$n,$v = $_ -split ','; if ($names -contains $n) {output}; $names+=$n; $values+=$v

Transposing a matrix from a 2D array

南笙酒味 提交于 2019-11-30 19:48:04
问题 I'm self teaching myself some java and I'm stuck on creating a 2D array that initializes it with random values and then creates the transpose of the array. An example output is: $ java Test1 22 333 44 555 6 Enter the number of rows (1-10): 0 ERROR: number not in specified range (1-10) ! and so on until you enter the correct number of rows and columns. Original matrix 1 22 333 44 555 6 Transposed matrix 1 333 555` 22 44 6` ^ Should be the final output. Some help with the code would appreciated

Transposing a table in SQL server

独自空忆成欢 提交于 2019-11-30 19:02:00
问题 I am using SQL Server 2005 for my application. I have a table in my stored procedure which has two columns, C1 and C2. I want to transpose this table such that the values of column C1 becomes the columns. Before transpose (Table 1): C1 C2 M1 U1 M1 U2 M1 U3 M2 U4 M2 U5 After Transpose (Table 2): M1 M2 U1 U4 U2 U5 U3 NULL In Table1, the number of distinct values (M1, M2) may vary. So, the columns in Table2 are not fix. Please provide a solution to achieve the same. 回答1: For this type of data

How do you transpose a dask dataframe (convert columns to rows) to approach tidy data principles

强颜欢笑 提交于 2019-11-30 18:24:46
问题 TLDR : I created a dask dataframe from a dask bag. The dask dataframe treats every observation (event) as a column. So, instead of having rows of data for each event, I have a column for each event. The goal is to transpose the columns to rows in the same way that pandas can transpose a dataframe using df.T. Details : I have sample twitter data from my timeline here. To get to my starting point, here is the code to read a json from disk into a dask.bag and then convert that into a dask

How to transpose MYSQL db in PHP

末鹿安然 提交于 2019-11-30 16:29:30
I am using PHP to query a MYSQL db to output data to a csv file. I am currently able to query the db and export the data to the CSV file. However i am unable to transpose the data so that the columns are rows, and rows are columns. CODE: function transpose($array) { if (!is_array($array) || empty($array)) { return array(); else { foreach ($array as $row_key => $row) { if (is_array($row) && !empty($row)) { //check to see if there is a second dimension foreach ($row as $column_key => $element) { $transposed_array[$column_key][$row_key] = $element; else { $transposed_array[0][$row_key] = $row;

Need to transpose a pandas dataframe

假如想象 提交于 2019-11-30 16:26:40
I have a Series that look like this: col1 id 0 a 10 1 b 20 2 c 30 3 b 10 4 d 10 5 a 30 6 e 40 My desired output is this: a b c d e 10 1 1 0 1 0 20 0 1 0 0 0 30 1 0 1 0 0 40 0 0 0 0 1 I got this code: import pandas as pd df['dummies'] = 1 df_ind.pivot(index='id', columns='col1', values='dummies') I get an error: 137 138 if mask.sum() < len(self.index): --> 139 raise ValueError('Index contains duplicate entries, ' 140 'cannot reshape') 141 ValueError: Index contains duplicate entries, cannot reshape There are duplicate id's because multiple values in col1 can be attributed to a single id. How