reshape

cannot reshape array of size 64 into shape (28,28)

我的未来我决定 提交于 2019-12-25 00:00:17
问题 Not able to reshape the image in mnist dataset using sklean This is the starting portion of my code just load the data some_digit = X[880] some_digit_image = some_digit.reshape(28, 28) ERROR PART ValueError Traceback (most recent call last) <ipython-input-15-4d618bdb57bc> in <module> 1 some_digit = X[880] ----> 2 some_digit_image = some_digit.reshape(28,28) ValueError: cannot reshape array of size 64 into shape (28,28) 回答1: You can only reshape it into a 8, 8 array. 8x8=64 回答2: try: some

Tensorflow python: reshape input [batchsize] to tensor [batchsize, 2] with specific order

China☆狼群 提交于 2019-12-24 21:49:34
问题 I have a tensor (shape=[batchsize]). I want to reshape the tensor in a specific order and into shape=[-1,2]. But I want to have: Element at [0,0] Element at [1,0] Element at [0,1] Element at [1,1] Element at [0,2] Element at [0,3] Element at [2,1] Element at [3,1] and so on for an unknow batchsize. Here is an example code with a tensor range=(0 to input=8). import tensorflow as tf import numpy as np batchsize = tf.placeholder(shape=[], dtype=tf.int32) x = tf.range(0, batchsize, 1) x = tf

R, data.table or dplyr, long format splitting colnames

佐手、 提交于 2019-12-24 18:05:11
问题 Imagine I have a dataframe with column names such as Mary1, Mary2, Mary3, Bob1, Bob2, Bob3, Pam1, Pam2, Pam3, and so on, but with many more columns. Let's put a simpler reproducible example. set.seed(1) mydata <- data.frame() mydata <- rbind(mydata,c(1,round(runif(30),3))) mydata <- rbind(mydata,c(2,round(runif(30),3))) mydata <- rbind(mydata,c(3,round(runif(30),3))) colnames(mydata) <- c("id", paste0(rep(LETTERS[1:10], each=3), 1:3)) that gives: id A1 A2 A3 B1 B2 B3 C1 C2 C3 D1 D2 D3 E1 E2

R ggplot2 stacked barplot by percentage with several categorical variables

旧街凉风 提交于 2019-12-24 07:10:16
问题 This is a simple question, but I'm having difficulty understanding the format required by ggplot2: I have the following data.table in R, print(dt) ID category A B C totalABC 1: 10 group1 1 3 0 4 2: 11 group1 1 11 1 13 3: 12 group2 15 20 2 37 4: 13 group2 6 12 2 20 5: 14 group2 17 83 6 106 ... My goal is to create a proportional stacked bar graph as in this example: https://rpubs.com/escott8908/RGC_Ch3_Gar_Graphs where the percentages of X/totalABC, where X is category_type either A, B, or C.

Merging multiple rows into single row

廉价感情. 提交于 2019-12-24 07:04:21
问题 I've some problems with my data frame in R. My data frame looks something like this: ID TIME DAY URL_NAME VALUE TIME_SPEND 1 12:15 Monday HOME 4 30 1 13:15 Tuesday CUSTOMERS 5 21 1 15:00 Thursday PLANTS 8 8 1 16:21 Friday MANAGEMENT 1 6 .... So, I want to write the rows, containing the same "ID" into one single row. Looking something like this: ID TIME DAY URL_NAME VALUE TIME_SPEND TIME1 DAY1 URL_NAME1 VALUE1 TIME_SPEND1 TIME2 DAY2 URL_NAME2 VALUE2 TIME_SPEND2 TIME3 DAY3 URL_NAME3 VALUE3 TIME

How to calculate anomalies of Geopotential Height in Matlab?

那年仲夏 提交于 2019-12-24 05:46:11
问题 I am interested in calculating GPH anomalies in Matlab. I have a 3D matrix of lat, lon, and time. Where time is a daily GPH value for 32 years (1979-2010). The matrix is 95x38x11689. How do I compute a daily average across all years for each day of data, when the matrix is 3D? I am ultimately trying to compute the GPH anomaly from the difference of the daily value and the climatological mean of that given day. In other words, how do I compute the average of Jan. 1st dates for all years to

Reshape data using dcast?

眉间皱痕 提交于 2019-12-24 04:51:49
问题 I don't know if using dcast() is the right way, but I want to reshape the following data.frame: df <- data.frame(x=c("p1","p1","p2"),y=c("a","b","a"),z=c(14,14,16)) df x y z 1 p1 a 14 2 p1 b 14 3 p2 a 16 so that it looks like this one: df2 <- data.frame(x=c("p1","p2"),a=c(1,1),b=c(1,0),z=c(14,16)) x a b z 1 p1 1 1 14 2 p2 1 0 16 The variable y in df should be broken so that its elements are new variables, each dummy coded. All other variables (in this case just z ) are equal for each person

How to reshape data from long to wide format

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-24 04:33:04
问题 I'm having trouble rearranging the following data frame: set.seed(45) dat1 <- data.frame( name = rep(c("firstName", "secondName"), each=4), numbers = rep(1:4, 2), value = rnorm(8) ) dat1 name numbers value 1 firstName 1 0.3407997 2 firstName 2 -0.7033403 3 firstName 3 -0.3795377 4 firstName 4 -0.7460474 5 secondName 1 -0.8981073 6 secondName 2 -0.3347941 7 secondName 3 -0.5013782 8 secondName 4 -0.1745357 I want to reshape it so that each unique "name" variable is a rowname, with the "values"

How to reshape data from long to wide format

谁说我不能喝 提交于 2019-12-24 04:33:02
问题 I'm having trouble rearranging the following data frame: set.seed(45) dat1 <- data.frame( name = rep(c("firstName", "secondName"), each=4), numbers = rep(1:4, 2), value = rnorm(8) ) dat1 name numbers value 1 firstName 1 0.3407997 2 firstName 2 -0.7033403 3 firstName 3 -0.3795377 4 firstName 4 -0.7460474 5 secondName 1 -0.8981073 6 secondName 2 -0.3347941 7 secondName 3 -0.5013782 8 secondName 4 -0.1745357 I want to reshape it so that each unique "name" variable is a rowname, with the "values"

Melt the data frame with 4 columns to three columns

倾然丶 夕夏残阳落幕 提交于 2019-12-24 04:26:09
问题 I have a data with 4 columns date , ville , borne and combined . I want to reshape this data to long format using reshape package. Head of data : > head(newdata) date ville borne comb 1 2010-01-01 00:00:00 46200 78500 124700 2 2010-01-01 01:00:00 46300 74100 120400 3 2010-01-01 02:00:00 46400 77600 124000 4 2010-01-01 03:00:00 46500 75600 122100 5 2010-01-01 04:00:00 46500 79000 125500 6 2010-01-01 05:00:00 46600 75500 122100 The reproducible data is as follows: newdata <- structure(list(date