reshape

ValueError: cannot reshape array of size 30470400 into shape (50,1104,104)

此生再无相见时 提交于 2019-12-18 01:19:53
问题 I am trying to run threw this Tutorial http://emmanuelle.github.io/segmentation-of-3-d-tomography-images-with-python-and-scikit-image.html where I want to do a Segmentation of 3-D tomography images with Python. I'm struggling directly in the beginning, with reshaping the image. This is the code: %matplotlib inline import numpy as np import matplotlib.pyplot as plt import time as time data = np.fromfile('/data/data_l67/dalladas/Python3/Daten/Al8Cu_1000_g13_t4_200_250.vol', dtype=np.float32)

How to reshape a dataframe with “reoccurring” columns?

£可爱£侵袭症+ 提交于 2019-12-17 19:25:34
问题 I am new to data analysis with R. I recently got a pre-formatted environmental observation-model dataset, an example subset of which is shown below: date site obs mod site obs mod 2000-09-01 00:00:00 campus NA 61.63 city centre 66 56.69 2000-09-01 01:00:00 campus 52 62.55 city centre NA 54.75 2000-09-01 02:00:00 campus 52 63.52 city centre 56 54.65 Basically, the data include the time series of hourly observed and modelled concentrations of a pollutant at various sites in "reoccurring columns

How do I convert a wide dataframe to a long dataframe for a multilevel structure with 'quadruple nesting'?

被刻印的时光 ゝ 提交于 2019-12-17 17:03:15
问题 I conducted a study that, in retrospect (one lives, one learns :-)) appears to generate multilevel data. Now I'm trying to restructure the dataset from wide to long so that I can analyse it using e.g. lme4. In doing so, I encounter an, um, challenge, that I've ran into a few times before, but for which I've never found a good solution. I've searched again this time, but I probably use the wrong keywords - or this problem is much rarer than I thought. Basically, in this dataset, the

reshape a pandas dataframe

寵の児 提交于 2019-12-17 16:47:09
问题 suppose a dataframe like this one: df = pd.DataFrame([[1,2,3,4],[5,6,7,8],[9,10,11,12]], columns = ['A', 'B', 'A1', 'B1']) I would like to have a dataframe which looks like: what does not work: new_rows = int(df.shape[1]/2) * df.shape[0] new_cols = 2 df.values.reshape(new_rows, new_cols, order='F') of course I could loop over the data and make a new list of list but there must be a better way. Any ideas ? 回答1: The pd.wide_to_long function is built almost exactly for this situation, where you

How do I stack only some columns in a data frame?

北城余情 提交于 2019-12-17 13:34:08
问题 I have some data in a data frame in the following form: A B C V1 V2 V3 1 1 1 x y z 1 1 2 a b c ... Where A,B,C are factors, and the combination A,B,C is unique for each row. I need to convert some of the columns into factors, to achieve a form like: A B C V val 1 1 1 V1 x 1 1 1 V2 y 1 1 1 V3 z 1 1 2 V1 a 1 1 2 V2 b 1 1 2 V2 c ... This seems to relate to both stack and the inverse of xtabs, but I don't see how to specify that only certain columns should be "stacked". 回答1: Using reshape2

How do I stack only some columns in a data frame?

只谈情不闲聊 提交于 2019-12-17 13:31:23
问题 I have some data in a data frame in the following form: A B C V1 V2 V3 1 1 1 x y z 1 1 2 a b c ... Where A,B,C are factors, and the combination A,B,C is unique for each row. I need to convert some of the columns into factors, to achieve a form like: A B C V val 1 1 1 V1 x 1 1 1 V2 y 1 1 1 V3 z 1 1 2 V1 a 1 1 2 V2 b 1 1 2 V2 c ... This seems to relate to both stack and the inverse of xtabs, but I don't see how to specify that only certain columns should be "stacked". 回答1: Using reshape2

Reshape multiple categorical variables to binary response variables

徘徊边缘 提交于 2019-12-17 11:45:17
问题 I am trying to convert the following format: mydata <- data.frame(movie = c("Titanic", "Departed"), actor1 = c("Leo", "Jack"), actor2 = c("Kate", "Leo")) movie actor1 actor2 1 Titanic Leo Kate 2 Departed Jack Leo to binary response variables: movie Leo Kate Jack 1 Titanic 1 1 0 2 Departed 1 0 1 I tried the solution described in Convert row data to binary columns but I could get it to work for two variables, not three. I would really appreciate if there is a clean way to do this. 回答1: An

How can I change the shape of a variable in TensorFlow?

醉酒当歌 提交于 2019-12-17 10:58:13
问题 TensorFlow tutorial says that at creation time we need to specify the shape of tensors. That shape automatically becomes the shape of the tensor. It also says that TensorFlow provides advanced mechanisms to reshape variables. How can I do that? Any code example? 回答1: Take a look at shapes-and-shaping from TensorFlow documentation. It describes different shape transformations available. The most common function is probably tf.reshape, which is similar to its numpy equivalent. It allows you to

Mysql, reshape data from long / tall to wide

吃可爱长大的小学妹 提交于 2019-12-17 10:44:50
问题 I have data in a mysql table in long / tall format (described below) and want to convert it to wide format. Can I do this using just sql? Easiest to explain with an example. Suppose you have information on (country, key, value) for M countries, N keys (e.g. keys can be income, political leader, area, continent, etc.) Long format has 3 columns: country, key, value - M*N rows. e.g. 'USA', 'President', 'Obama' ... 'USA', 'Currency', 'Dollar' Wide format has N=16 columns: county, key1, ..., keyN

can the value.var in dcast be a list or have multiple value variables?

送分小仙女□ 提交于 2019-12-17 09:29:10
问题 In the help files for dcast.data.table , there is a note stating that a new feature has been implemented: "dcast.data.table allows value.var column to be of type list" I take this to mean that one can have multiple value variables within a list, i.e. in this format: dcast.data.table(dt, x1~x2, value.var=list('var1','var2','var3')) But we get an error: 'value.var' must be a character vector of length 1. Is there such a feature, and if not, what would be other one-liner alternatives? EDIT: In