transpose

Numpy Performance - Outer Product of a vector with its transpose

冷暖自知 提交于 2019-12-02 03:07:40
It is my understanding that the Outer Product of a vector with its transpose is symmetric in value. Does Numpy take this into account to only do the multiplications for the upper triangle part of the output or does it calculate the whole output matrix (even though it is symmetric and time + memory could go to waste?) Exploring some alternatives: In [162]: x=np.arange(100) In [163]: np.outer(x,x) Out[163]: array([[ 0, 0, 0, ..., 0, 0, 0], [ 0, 1, 2, ..., 97, 98, 99], [ 0, 2, 4, ..., 194, 196, 198], ..., [ 0, 97, 194, ..., 9409, 9506, 9603], [ 0, 98, 196, ..., 9506, 9604, 9702], [ 0, 99, 198, ..

HIVE Pivot and Sum

只谈情不闲聊 提交于 2019-12-02 02:58:15
问题 I have a table that I am trying to figure out how to pivot and sum based on the values in a second column. Example input: |own|pet|qty| |---|---|---| |bob|dog| 2 | |bob|dog| 3 | |bob|dog| 1 | |bob|cat| 1 | |jon|dog| 1 | |jon|cat| 1 | |jon|cat| 1 | |jon|cow| 4 | |sam|dog| 3 | |sam|cow| 1 | |sam|cow| 2 | Example output: |own|dog|cat|cow| |---|---|---|---| |bob| 6 | 1 | | |jon| 1 | 2 | 4 | |sam| 1 | | 3 | 回答1: Use case and sum() : select own, sum(case when pet='dog' then qty end) as dog, sum

HIVE Pivot and Sum

心已入冬 提交于 2019-12-02 02:21:27
I have a table that I am trying to figure out how to pivot and sum based on the values in a second column. Example input: |own|pet|qty| |---|---|---| |bob|dog| 2 | |bob|dog| 3 | |bob|dog| 1 | |bob|cat| 1 | |jon|dog| 1 | |jon|cat| 1 | |jon|cat| 1 | |jon|cow| 4 | |sam|dog| 3 | |sam|cow| 1 | |sam|cow| 2 | Example output: |own|dog|cat|cow| |---|---|---|---| |bob| 6 | 1 | | |jon| 1 | 2 | 4 | |sam| 1 | | 3 | Use case and sum() : select own, sum(case when pet='dog' then qty end) as dog, sum(case when pet='cat' then qty end) as cat, sum(case when pet='cow' then qty end) as cow from your_table group by

Transpose Function in R is not transposing

雨燕双飞 提交于 2019-12-02 01:26:22
Trying to transpose a vector in R and then name it. I created a vector, v as follows: v<-c(1,2,3,4) But when I try to transpose as: t(v) It gives the output: t(v) [,1] [,2] [,3] [,4] [1,] 1 2 3 4 I know I can create a matrix or define a vector the other way, but I think the bigger issue is why transpose itself is not working. I do not have any packages installed or things like that. #Create data v<-c(1,2,3,4) #In addition to the answers presented prior to mine, you could do this. t(t(v)) [,1] [1,] 1 [2,] 2 [3,] 3 [4,] 4 来源: https://stackoverflow.com/questions/51201856/transpose-function-in-r

Memory efficient transpose - Awk

时光怂恿深爱的人放手 提交于 2019-12-02 00:05:49
i am trying to transpose a table (10k rows X 10K cols) using the following script. A simple data example $ cat rm1 t1 t2 t3 n1 1 2 3 n2 2 3 44 n3 1 1 1 $ sh transpose.sh rm1 n1 n2 n3 t1 1 2 1 t2 2 3 1 t3 3 44 1 However, I am getting memory error. Any help would be appreciated. awk -F "\t" '{ for (f = 1; f <= NF; f++) a[NR, f] = $f } NF > nf { nf = NF } END { for (f = 1; f <= nf; f++) for (r = 1; r <= NR; r++) printf a[r, f] (r==NR ? RS : FS) }' Error awk: cmd. line:2: (FILENAME=input FNR=12658) fatal: dupnode: r->stptr: can't allocate 10 bytes of memory (Cannot allocate memory) Here's one way

Transforming a list to a column vector in Python

ぃ、小莉子 提交于 2019-12-01 21:42:51
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 ) 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 brackets) >>> np.array([X]).T If you want to convert a Python list into a numpy column vector, you can use the

transpose nested list

為{幸葍}努か 提交于 2019-12-01 20:10:43
问题 I have a list structure which represents a table being handed to me like this > l = list(list(1, 4), list(2, 5), list(3, 6)) > str(l) List of 3 $ :List of 2 ..$ : num 1 ..$ : num 4 $ :List of 2 ..$ : num 2 ..$ : num 5 $ :List of 2 ..$ : num 3 ..$ : num 6 And I'd like to convert it to this > lt = list(x = c(1, 2, 3), y = c(4, 5, 6)) > str(lt) List of 2 $ x: num [1:3] 1 2 3 $ y: num [1:3] 4 5 6 I've written a function that does it in a really simple manner which uses Reduce , but I feel like

how to do Transpose in corresponding few columns in pig/hive

血红的双手。 提交于 2019-12-01 19:55:49
I was wondering is it possible to do transposition corresponding few columns in pig/hive. as dealing with data i got below requirement id jan feb march 1 j1 f1 m1 2 j2 f2 m2 3 j3 f3 m3 where i need to transpose it against first column, so it would look like - id value month 1 j1 jan 1 f1 feb 1 m1 march 2 j2 jan 2 f2 feb 2 m2 march 3 j3 jan 3 f3 feb 3 m3 march I have tried this with java, but to get it into distributed mode is there any way to do it in pig/hive. appreciating your help in advance!! Pig doesn't have any built-in function to solve your requirement, but you can try the below

SAS Safe Column Names

家住魔仙堡 提交于 2019-12-01 18:34:15
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. 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 be used to refer to them: options validvarname=any; /* Create dataset and transpose it */ data zz; var1 =

mysql, transpose/pivot row to column, variable selects

我的梦境 提交于 2019-12-01 12:47:16
Hello again and thank you in advance for your help. I've checked a few prior questions and couldn't find this exact situation. I'm trying to transpose/pivot a row to column, but the results are based on a date function in the where clause, making my selects somewhat variable. SELECT DATE_FORMAT(packet_details.installDate,'%m-%d-%Y') as Install_Date, Count(packet_details.installDate) FROM packet_details WHERE packet_details.installDate >= CURRENT_DATE - INTERVAL 7 DAY AND packet_details.installDate "*lessthan*" CURRENT_DATE + INTERVAL 7 DAY GROUP BY installDate *lessthan symbol wont show here