# Questions tagged [reshape]

In R, Matlab and Numpy, reshape functions allow data to be transformed into more convenient forms.

2,326 questions

**0**

votes

**0**answers

16 views

### How do I split a text columns rows base on a delimiter or phrase and keep the name on each split?

I have a movies review dataframe with two columns: Name of Movie and Review. I want to split the review into sentences based on delimiter .,?! or a phrase. I then want to take that split review and ...

**0**

votes

**0**answers

19 views

### Python/Pandas-Help reshaping lone to wide [duplicate]

I am trying to do the following transformation in Pandas, but cannot figure it out. It seems to be a mix of long to wide with pivoting involved.
Any help would be appreciated.
From:
H C CN Y1 ...

**-1**

votes

**2**answers

37 views

### Reshape 3 Column Data with ID

I'm trying to created a directed network graph in R. To do this I need to create a matrix of what nodes are connected.
SOURCE_SUBREDDIT TARGET_SUBREDDIT LINK_SENTIMENT
rddtgaming ...

**0**

votes

**0**answers

9 views

### Reshape layer for keras doesn't seem to work as intended, giving an expected dimension error

So I am attempting to perform training on an FCN8 model on images of shape (3, 224, 224), but am encountering an issue with the Reshape layer right before the Activation layer. It doesn't seem to be ...

**0**

votes

**0**answers

26 views

### How to convert MNIST dataset to 3 channel?

I am working on a Transfer Learning Project and am trying to substitute the original Flower dataset with the MNIST dataset to detect the numbers. I am following the Program : Original Program Section ...

**1**

vote

**1**answer

35 views

### PyTorch: apply mapping over singleton dimension of tensor

I'm afraid the title is not very descriptive but I could not think of a better one. Essentially my problem is the following:
I have a pytorch tensor of shape (n, 1, h, w) for arbitrary integers n, h ...

**1**

vote

**1**answer

29 views

### How to reshape dataframe and transpose recurring columns to dataframe rows?

I have a dataframe that has recurring columns (the interval is 5).
my dataframe at the moment
So this is how it looks: I have 5 type of columns and they repeat time over time. The recurring ...

**0**

votes

**1**answer

63 views

### R: How can I transpose a selection of every 5 rows into a single row?

I have a dataset in the following (tidy) format:
SAMPLE, MARKER, ALLELE, LENGTH, PEAK
BRIS01, B100, allele 1, NA, 126.95
BRIS01, B100, allele 2, 160, 159.72
BRIS01, B100, allele 3, 162, 162.01
BRIS02,...

**-1**

votes

**1**answer

19 views

### Why does it fail to reshape an array with shape (60000, 10, 1) to (60000, 10)?

I'm learning tensorflow lessons in one of which there's a step to reshape a numpy array with shape (60000, 10, 1) into shape (60000, 10). But it seems the shape not changed after calling ndarray....

**1**

vote

**1**answer

23 views

### reshape long to wide format dropping some rows

I have 5 column data frame which I would like to convert some columns from long to wide format
I have tried reshap and tidyverse and can get close but lose some rows when converting. I have the ...

**1**

vote

**1**answer

43 views

### Pivoting (reshaping) a pandas dataframe in alphabetical case-insensitive order

I have a dataframe with 3 columns: variable1, variable2, value.
value is measured from all possible combinations of variable1 and variable2 (all-against-all). Also, variable1 and variable2 have the ...

**0**

votes

**1**answer

15 views

### Cannot reshape image into 2d array in Python

I am trying to reshape an image into a long 2d array (nrow * ncol, nband) with the following code:
new_shape = (img.shape[0] * img.shape[1], img.shape[2] - 1)
img_as_array = img[:, :, :7].reshape(...

**-1**

votes

**1**answer

23 views

### Reshape large data set from long to wide [duplicate]

I want to reshape a large data set i have from a long to a wide format. Currently my data set is formed as follows:
df <- structure(list(Politician = c("1", "2", "3", "k", "1", "2", "3",
"k"), ...

**2**

votes

**1**answer

91 views

+50

### expected input_1 to have 3 dimensions, but got array with shape (3, 4)

This is a simplified version of my code which throws the error mentioned in the title:
import tensorflow as tf
BATCH_SIZE = 3
SEQ_LENGTH = 4
NUM_CLASSES = 2
LSTM_UNITS = 64
NUM_SHARDS = 4
...

**1**

vote

**1**answer

35 views

### How can I reshape this multi-dimensional list to a 2D array?

I know this has been asked dozens of times, and I've tried to get the intuition (here, here) of working with multi-dimensional arrays but I can't figure out the process.
I am getting days, weeks, ...

**0**

votes

**0**answers

15 views

### How to fix 'cannot reshape array of size 30233088 into shape (1,64,64,3)' error in python?

I convert the image to rgb format after which I want to resize it to the size I'm interested in but the error below appears
I tried the following function:
def predict(graph):
im = Image.open("...

**1**

vote

**0**answers

25 views

### Numpy and inverse matrices - Method to do only one reshape insruction

I am doing a batch execution of high number of 3x3 matrices with CUDA.
The goal is to get a big matrix of 3x3 matrix (so I use a 4D array).
I have done previously the same operation with numpy....

**2**

votes

**2**answers

36 views

### Reordering pandas dataframe data for a multiindex after pivot

I'm building an analysis tool for public transportation data and want to reorder data in a pandas dataframe that can be best explained using the following example:
My initial shape of data is:
...

**1**

vote

**1**answer

42 views

### tidyr:: gather multiple columns different types

I'm trying to convert from wide to long format using tidyr to gather multiple columns with different types. Essentially the same thing as the question asked here. I'm new to R and not familiar with ...

**1**

vote

**1**answer

36 views

### Reshape function broadcasting from wrong numpy shape

I am trying to reshape a numpy.array from shape (4,4) to shape (2,2,2,2). The error I am receiving is:
ValueError: could not broadcast input array from shape (2,2,2,2) into shape (4,4).
This makes ...

**3**

votes

**2**answers

55 views

### How to reshape this array the way I need?

I'm looking to reshape an array of three 2x2 matrices, that is of shape (3,2,2) i.e.
a = np.array([[[a1,a2],[a3,a4]],
[[b1,b2],[b3,b4]],
[[c1,c2],[c3,c4]]])
to this array ...

**2**

votes

**1**answer

36 views

### Reshape np.array based on the default size

There are 2 np.arrays and I would like to reshape np.array1 from shape (12,)in reference to array2 with shape (4,):
array1 = np.array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) and
array1....

**0**

votes

**2**answers

66 views

### What mathematical function does reshape perform?

In both Python and MATLAB you can use a function called reshape() to change the dimensions of the matrix.
What operation is this in linear algebra, is this a change of basis, or a more simple matrix ...

**2**

votes

**2**answers

22 views

### Reshaping csv with Pandas: joining two subsets of df

My .csv looks like:
Res X XB XC O P
A312 76.55 - - - -
B313 175.4 62.28 32.62 8.189 121.2
...

**0**

votes

**1**answer

40 views

### Reshaping Time Series Data with Multiple Features for RNNs

I have a time series data set with 3 measurement variables and with about 2000 samples. I want to classify samples into 1 of 4 categories using a RNN or 1D CNN model using Keras in R. My problem is ...

**0**

votes

**1**answer

30 views

### Converting a pandas dataframe column from long to wide when there are multiple values per group

I have the following dataframe with the following format:
df = pd.DataFrame({'Date': np.repeat(['20190101', '20190102'], 8),
'Category': list(np.repeat(['A', 'B'], 4))*2,
...

**1**

vote

**1**answer

23 views

### Make one column into multiple columns in R [duplicate]

I have a dataset that looks something like this:
Name Result
X1 Red
X2 Blue
X2 Green
X3 Red
X2 Yellow
X3 Blue
and I would like the values in the "Name" column to turn into their own ...

**0**

votes

**1**answer

28 views

### convert summarized data frame from long to wide (without using reshape, reshape2, tydr)

Introduction:
I work in a strict environment where I can not install any more packages. I have access to dcast(), xtabs(), reshape() from {stats}. I don't have access to tydr, reshape nor reshape2 ...

**0**

votes

**0**answers

15 views

### Reshape pandas dataframe where column categories become separate columns [duplicate]

I want to change reshape Pandas data frame. I used stack() and tried other different way but could not do this.
My data frame is following.
data = [[1, 'Electricity', 100], [1, 'Water', 10],[1, 'LPG'...

**2**

votes

**2**answers

53 views

### Reverse stacking operation on NumPy array

I'm have a line of code that efficiently reshapes a numpy array from a 400x8x8 array to a 160x160 array and I need to reverse the process but can't figure out the reverse of the line.
I can already ...

**0**

votes

**0**answers

37 views

### Reshaping the data-frame and then populating it

I have a data frame with 201189 observation and 5 variables: comm_id,price,currency,create_date and uom. There are 288 unique comm_id and 2549 unique create_date.The comm_ids and create date are ...

**0**

votes

**2**answers

132 views

### converting an array of size (n,n,m) to (None,n,n,m)

I am trying to reshape an array of size (14,14,3) to (None, 14,14,3). I have seen that the output of each layer in convolutional neural network has shape in the format(None, n, n, m).
Consider that ...

**-1**

votes

**2**answers

271 views

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

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 ...

**0**

votes

**4**answers

403 views

### Sequentially rename duplicate value in character variable before reshaping it with dcast

I'm scrapping cars information from a website and I'm getting not constant and not so clean data from it. I'm trying to clean and arrange this data into a data frame.
For example:
dd <- data....

**0**

votes

**1**answer

59 views

### Reshape dataframe to be three columns wide without knowing variable names

I have a dataframe with unknown column names, but a consistent format. How can I reshape it to be three columns wide without using column names?
cpu[,1:6]
Datapoints.Timestamp Datapoints.Maximum ...

**0**

votes

**1**answer

57 views

### Error when checking target: expected dense_24 to have 3 dimensions, but got array with shape (3283, 1)

I have an X_train = [(4096, 18464),(4097, 43045),(4098, 38948),(4099, 2095),(4100, 59432),(4101, 55338),(4102, 51245),(4103, 26658),(4104, 30755),....] with a shape (3283, 2) and
y_train = [19189, ...

**1**

vote

**2**answers

49 views

### Numpy array - stack multiple columns into one using reshape

For a 2D array like this:
table = np.array([[11,12,13],[21,22,23],[31,32,33],[41,42,43]])
Is it possible to use np.reshape on table to get an array single_column where each column of table is ...

**-1**

votes

**0**answers

39 views

### Changing many column in a data frame to one using pandas

I have a data set from gapminder.org that contains many columns the first one is the country name then the rest are years each column is one year and the values in the cells are the child mortality
...

**0**

votes

**1**answer

58 views

### pandas reshape long based on prefixes

I have a Pandas dataframe with the following columns
game_id, date, country, winner_name, winner_age, ... winner_ranking, loser_name, loser_age, ... loser_ranking
1 1/2/10 UK . Ben ...

**0**

votes

**3**answers

76 views

### Understanding the differences between similar numpy flattening techniques

I'm working through the homework assignment for week 2 of the first course in the deeplearning.ai certificate on Coursera.
One of the first tasks is to flatten an image (209, 64, 64, 3). You can do ...

**0**

votes

**3**answers

35 views

### How to reshape an array of shape (N , N) dimension to (N , N , 3)

I have an array of shape ( 2084, 2084) i want to reshape it to (2084, 2084 , 3). I tried using np.dstack but it gives me something like this (1, 2084, 2084)
patch = (2084, 2084)
patch_new = np.dstack(...

**1**

vote

**1**answer

25 views

### How do I change the structure of a time-series table from row to column?

So I have a table that is in the following format:
date <- c('t1','t1','t1','t2','t2','t2')
factor <- c('a','b','c','a','b','c')
beta <- c(1,2,4,3,5,2)
df <- data.frame(date, factor, ...

**1**

vote

**1**answer

39 views

### Numpy: reshape uneven 1D array to 2D array for byte plotting

This might be too easy for everyone, but as I mentioned in the subject, is there a way to reshape an uneven 1D numpy array to 2D numpy array?
When I say uneven 1D array, the shape is (34191,) and this ...

**0**

votes

**0**answers

22 views

### Pandas pivot or reshape [duplicate]

I have a panda DF as follows:
items_type item_id item_name item_price
A 1 x 1.0
A 2 y 1.1
A 3 z ...

**2**

votes

**1**answer

46 views

### numpy reshape question (matlab comparison)

Say I have a 1-D vector named s composed of 0,3,6,9.
In MATLAB the shape is denoted (1,4). i.e. a 1x4 row vector.
But in numpy the shape is given as (4,). Why? Shouldn't this notation denote a 4x1 ...

**0**

votes

**2**answers

21 views

### Expanding an array along particular dimension

I have an array as below:
arr = np.arange(2*1*15).reshape(2, 1, 15)
Now, how can I expand this array to shape (2, 10, 15). To fill in the values it'd be okay to use the same values as in the (1, 15) ...

**1**

vote

**3**answers

39 views

### How can I convert an array of images to a 2D array in Python

I have a numpy array of images in that shape:
(50000, 32, 32, 3)
50000 is the number of images
32, 32 are the height and width
3 are the RGB values with a range of 0-1
I would like to convert it to ...

**2**

votes

**2**answers

47 views

### Reshape origin destination data

I need to turn this data frame :
df1 <- data.frame(A = c(1,2,3), B = c(2,1,4), Flow = c(50,30,20))
into a data frame like this :
df2 <- data.frame(A = c(1,3), B = c(3,4), AtoB = c(50,20), ...

**0**

votes

**1**answer

25 views

### reshape a matrix in R and converting every n rows into one row

I have a data frame df like:
year location
1 A
2 B
3 C
------------------
1 X
5 A
10 F
------------------
3 F
5 x
2 ...

**-1**

votes

**0**answers

27 views

### difference between tf.placeholder(tf.float32, [None, ]) and tf.placeholder(tf.float32, [None])

I know tf.placeholder(tf.float32, [None]) means input is expected to be 1-d array, but what effects adding a comma has like in tf.placeholder(tf.float32, [None, ])