transpose

How to transpose a matrix in prolog

最后都变了- 提交于 2019-11-28 01:09:57
How can I transpose a list like [[1,2,3][4,5,6][6,7,8]] to [[1,4,6],[2,7,8],[3,6,9]] ? To depict it: I'd like to flip the matrix 90 degree to the left. How can I do that? Not sure your example is correct, but I get the idea. If using SWI-PROLOG, you can use the CLPFD module , like so: :- use_module(library(clpfd)). Allowing you to use the transpose/2 predicate, like this: 1 ?- transpose([[1,2,3],[4,5,6],[6,7,8]], X). X = [[1, 4, 6], [2, 5, 7], [3, 6, 8]]. Otherwise (if no SWI-PROLOG), you could simply use this implementation (which happened to be an old one in SWI's clpfd): transpose([], []).

SQL Server Pivot multiple columns based on one column

╄→尐↘猪︶ㄣ 提交于 2019-11-27 20:13:14
I have following source and destination tables in sql server 2008R2. How can I do pivot(s) in TSQL to get to the destination from source. SourceTbl empId empIndex empState empStDate empEndDate ======================================================== 10 1 AL 1/1/2012 12/1/2012 10 2 FL 2/1/2012 2/1/2013 15 1 FL 3/20/2012 1/1/2099 DestTbl empId empState1 empState1StDate empState1EndDt empState2 empState2StDate empState2EndDt ========================================================================================================= 10 AL 1/1/2012 12/1/2012 FL 2/1/2012 2/1/2013 15 FL 3/20/2012 1/1

Transposing a dataframe maintaining the first column as heading

纵饮孤独 提交于 2019-11-27 20:08:23
问题 I have a big dataframe, but small example would be like this: mydf <- data.frame(A = c(letters[1:10]), M1 = c(11:20), M2 = c(31:40), M3 = c(41:50)) I want to transpose the dataframe and maintain the column 1 (A) as column heading ( letter[1:10]) as variable names. The following are scratch trials of unsuccessful codes. tmydf = data.frame(t(mydf)) names(tmydf) <- tmydf[1,] Thanks; 回答1: Here is one way tmydf = setNames(data.frame(t(mydf[,-1])), mydf[,1]) 回答2: Something like this perhaps: tmp <-

How do I transpose a tibble() in R [duplicate]

对着背影说爱祢 提交于 2019-11-27 18:08:10
问题 This question already has an answer here: Transposing data frames 1 answer 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 I try to re-make a transposed version of my tibble. Question: What is the simplest way to transpose a tibble where the first column should become the column names of the

Rotate - Transposing a List<List<string>> using LINQ C#

允我心安 提交于 2019-11-27 15:48:49
I'm having a List<List<string>> , 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<List<string>> PersonInfo = new List<List<string>>() { new List<string>() {"John", "Peter", "Watson"}, new List<string>() {"1000", "1001", "1002"} } Appropriate Screen Shot: Existing I need to rotate the data as like the below Screenshot: Proposed Kindly assist me how to rotate the data using LINQ C# This is a simple and flexible solution, it will handle multiple inner lists with any number of dimensions. List

Use a dope vector to access arbitrary axial slices of a multidimensional array?

落爺英雄遲暮 提交于 2019-11-27 15:44:25
I'm building a suite of functions to work with a multidimensional-array data structure and I want to be able to define arbitrary slices of the arrays so I can implement a generalized inner product of two arbitrary matrices (aka Tensors or n-d arrays ). An APL paper I read (I honestly can't find which -- I've read so many) defines the matrix product on left-matrix X with dimensions A;B;C;D;E;F and right-matrix Y with dimensions G;H;I;J;K where F==G as Z <- X +.× Y Z[A;B;C;D;E;H;I;J;K] <- +/ X[A;B;C;D;E;*] × Y[*;H;I;J;K] where +/ is sum of , and × applies element-by-element to two vectors of the

MySql Transpose Row into Column and Column into Row [duplicate]

扶醉桌前 提交于 2019-11-27 14:52:42
This question already has an answer here: MySQL pivot table 8 answers i have problem with transposing row to column and column to row. I can do that if it just transpose row to column or column to row. This my table with data UNIT|JAN|FEB|MAR|APR|MEI|JUN CS-1|100|200|300|400|500|600 CS-2|111|222|333|444|555|666 CS-3|331|123|423|923|918|123 and I would like to get the following output MONTH|CS-1|CS-2|CS-3 JAN |100 |111 |331 FEB |200 |222 |123 MAR |300 |333 |423 etc.. Anybody know how to do this? Thanks very much! You can do it this way SELECT month, MAX(CASE WHEN unit = 'CS-1' THEN value END)

SQL: Real Transpose

隐身守侯 提交于 2019-11-27 14:52:00
I know about pivot and unpivot. That is not what I want. Pivot and unpivot aggregate data, but that is not what I want. Think of a table as a matrix (linear algebra). If I start with an m x n matrix, I want to convert that matrix (table) into an n x m matrix. I want a true TRANSPOSE . How can I do this in SQL? For example if I have: 1 2 3 1 2 4 6 7 8 3 2 1 3 9 1 then the result should be: 1 1 6 3 3 2 2 7 2 9 3 4 8 1 1 Notice that the number of rows becomes the number of columns, and vice versa. Also notice that I have not grouped or aggregated any of the data. Every single value present in the

Matrix expression causes error “requires numeric/complex matrix/vector arguments”?

不羁岁月 提交于 2019-11-27 14:37:49
ma=diag(3)+t(da)%*%da R Code above, error message as follows: Error in t(da) %*% da : requires numeric/complex matrix/vector arguments da is a matrix, looks as following: V45 V46 V47 V48 V49 V50 V51 1 0.461727059 2.357732985 -1.536932071 -1.34425710 0.893541975 -0.0676913075 -0.86532231 2 0.253022555 1.524473647 -0.588911138 -1.65207275 -0.072255170 -0.5212951533 -1.43686625 3 0.824678362 1.497001189 0.335973892 -0.84027799 0.275289411 -0.2921928001 -0.16277595 4 0.854530787 2.258305198 0.107346531 -1.69194014 -0.841572928 -1.1153931009 -1.939461341 5 1.148286984 -0.232390389 -0.498465734 -0

How to transpose a dataset in a csv file?

我与影子孤独终老i 提交于 2019-11-27 07:28:23
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. If the whole file contents fits into memory, you can use import csv from itertools import izip a = izip(*csv.reader(open("input.csv", "rb"))) csv.writer(open("output.csv", "wb")).writerows(a) You can basically think of zip() and izip() as transpose operations: a = [(1, 2, 3), (4, 5, 6), (7, 8, 9)] zip(*a) # [(1, 4, 7), # (2, 5, 8), # (3, 6, 9)] izip() avoids the immediate copying of the