reshape

How to transform R data from long-ish to wide-ish [duplicate]

喜你入骨 提交于 2019-12-13 02:58:10
问题 This question already has answers here : Convert data from long format to wide format with multiple measure columns (5 answers) Closed 23 days ago . I am using R to try to transform my data frame from "long-ish" to "wide-ish" and I have searched in vain for an answer that uses data similar in structure to mine. Here are my data: | ID | NAME | V1 | V2 | V3 | |------|------|-------|----:|-----:| | 1001 | Bob | Red | 302 | 0.50 | | 1001 | Bob | Blue | 737 | 0.50 | | 1002 | Jim | Red | 432 | 0.14

In Keras, how to use Reshape layer with None dimension?

倾然丶 夕夏残阳落幕 提交于 2019-12-13 01:16:19
问题 In my model, a layer has a shape of [None, None, 40, 64] . I want to reshape this into [None, None, 40*64] . However, if I simply do the following: reshaped_layer = Reshape((None, None, 40*64))(my_layer) It throws an error complaining that None values not supported . (Just to be clear, this is not tf.keras , this is just Keras). 回答1: First of all, the argument you pass to Reshape layer is the desired shape of one sample in the batch and not the whole batch of samples. So since each of the

How to reshape matlab matrices for this example?

淺唱寂寞╮ 提交于 2019-12-12 21:28:51
问题 I have a 40x16 matrix or 8 5x16 one below the other i.e. aligned vertically. I want to get a 5x128 matrix from that such that I align the 8 5x16 matrices horizontally. is there an efficient/quicker (rather than the hardcoded for loops) way to do this? I want the individual 5x16 matrices intact. 回答1: This should work. Suppose your matrix is A (40x16). Here's a way using reshape : m = 5; n = 8; p = 16; B = reshape(permute(reshape(A', p, m, n), [2 1 3]), m, n*p); B will have your eight 5x16

Reshape 4D numpy array into 3D

a 夏天 提交于 2019-12-12 18:31:43
问题 I have a numpy array with the following dimensions - (256, 128, 4, 200) - basically the first two can form an image, the third is channels and the fourth is frames ("time instances"). How can I reshape the array so the frames are "stacked" one after the other, in other words the array would have a shape of (256, 128*200, 4)? It is important that the concatenating is frame-wise, so the order of the values in a frame is preserved. Essentially, what is needed is to optimize: data_new = data[:, :

Melt a pandas DataFrame

房东的猫 提交于 2019-12-12 15:11:33
问题 I have a pandas DataFrame like this: df = pd.DataFrame({'custid':[1,2,3,4], ...: 'prod1':['jeans','tshirt','jacket','tshirt'], ...: 'prod1_hnode1':[1,2,3,2], ...: 'prod1_hnode2':[6,7,8,7], ...: 'prod2':['tshirt','jeans','jacket','shirt'], ...: 'prod2_hnode1':[2,1,3,4], ...: 'prod2_hnode2':[7,6,8,7]}) In [54]: df Out[54]: custid prod1 prod1_hnode1 prod1_hnode2 prod2 prod2_hnode1 \ 0 1 jeans 1 6 tshirt 2 1 2 tshirt 2 7 jeans 1 2 3 jacket 3 8 jacket 3 3 4 tshirt 2 7 shirt 4 prod2_hnode2 0 7 1 6

Using melt / cast with variables of uneven length in R

◇◆丶佛笑我妖孽 提交于 2019-12-12 12:22:46
问题 I'm working with a large data frame that I want to pivot, so that variables in a column become rows across the top. I've found the reshape package very useful in such cases, except that the cast function defaults to fun.aggregate=length. Presumably this is because I'm performing these operations by "case" and the number of variables measured varies among cases. I would like to pivot so that missing variables are denoted as "NA"s in the pivoted data frame. So, in other words, I want to go from

How to pivot a table to make columns fro a variable row values in R

我是研究僧i 提交于 2019-12-12 08:12:52
问题 I have a data.frame with the columns: Month, Store and Demand. Month Store Demand Jan A 100 Feb A 150 Mar A 120 Jan B 200 Feb B 230 Mar B 320 I need to pivot it around to make a new data.frame or array with columns for each month, store e.g.: Store Jan Feb Mar A 100 150 120 B 200 230 320 Any help is very much appreciated. I have just started with R. 回答1: > df <- read.table(textConnection("Month Store Demand + Jan A 100 + Feb A 150 + Mar A 120 + Jan B 200 + Feb B 230 + Mar B 320"), header=TRUE

How to transform long to wide data in Stata?

点点圈 提交于 2019-12-12 06:20:01
问题 I have this data: id test test_date value 1 A 02/06/2014 12:26 11 1 B 02/06/2014 12:26 23 1 C 02/06/2014 13:17 43 1 D 02/06/2014 13:17 65 1 E 02/06/2014 13:17 34 1 F 02/06/2014 13:17 64 1 A 05/06/2014 15:14 234 1 B 05/06/2014 15:14 646 1 C 05/06/2014 16:50 44 1 E 05/06/2014 16:50 55 2 E 05/06/2014 16:50 443 2 F 05/06/2014 16:50 22 2 G 05/06/2014 16:59 445 2 B 05/06/2014 20:03 66 2 C 05/06/2014 20:03 77 2 D 05/06/2014 20:03 88 2 E 05/06/2014 20:03 44 2 F 05/06/2014 20:19 33 2 G 05/06/2014 20

Creating a super matrix using openCV

青春壹個敷衍的年華 提交于 2019-12-12 04:51:51
问题 I have to create a 4800 x 5 super matrix. This matrix will consist of 5 images of size 80 x 60 which I have already reshaped into matrices of 4800 x 1 using cvReshape. Therefore, I would now like to place these images next to the other to get a super matrix of dimensions 4800 x 5. How can I go about doing this using openCV? I have been trying all a long while now and this is due soon but I am no closer to achieving the creation of this matrix. I would really appreciate if someone could please

Tensorflow: Feeding every LSTM timestep into the same logit layer (generaly feeding a dynamic amount of tensors into one layer)

南笙酒味 提交于 2019-12-12 04:48:20
问题 I stumbled upon this issue while trying to build an LSTM-classifier. Using tf.nn.dynamic_rnn to auto-unfold over time i get an output lstm_output of size [batch_size, time_steps, number_cells] from the lstm cell (ignoring the state which is also an output). Now this output should for every timestep be fed into the same fully connected layer (planned to use tf.contrib.layers.fully_connected(lstm_output_oneTimestep, numClasses) to reduce the size from number_cells to number_classes (for using