Skip to main content

Questions tagged [reshape]

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

0 votes
0 answers
15 views

Unexpected coordinate switching when reshaping object positions into 3D grid after flattening and integrating

I am working on processing and analyzing velocity field data from VTI files using Python. The workflow includes reading VTI files, extracting velocity data, computing object trajectories, generating ...
Toto's user avatar
  • 11
-3 votes
0 answers
39 views

cannot reshape array of size 1000 into shape (100,100) [closed]

>>> cent_rand = np.random.randint(1919, 3946, 1000) >>> len(cent_rand) 1000 >>> two_d_cent = cent_rand.reshape((100,100)) Traceback (most recent call last): File "<...
rosa elena's user avatar
0 votes
0 answers
14 views

Why reshape is needed for Sequential models after minmaxscaler class? and how to use?

My recent project is based on 'Stock Prediciton" I'm working on df["Open"] as nd.array. Trying to understand intuitively how this works and whether my predicted data will be correct or ...
Shreeya Sharma's user avatar
0 votes
2 answers
33 views

merge multiple DFs based on column names and row names in R [duplicate]

I have 3 Dfs I need to split it based on columns and row names like shown below I tried merge_recurse option from reshape, looks like it merges row by row. Please help me to get the columns added side ...
Shyamili's user avatar
1 vote
3 answers
58 views

Equivalence between reshape, strides and transpose? (numpy)

i am sorry for the very naive question. I have these lines of numpy code, with a transpose at the beginning, and strides and reshape are used afterward. I wonder if by re-ordering indices in reshape ...
pierre_j's user avatar
  • 939
1 vote
1 answer
29 views

R issue with reshape, reshape is not ordering columns correctly

I am trying to use reshape function in R to arrange my data timepoints in a table. The variable that I am using to split it is numerical, but when reshape arranges the table it incorrectly puts 2,0.5,...
Gabriela Toomer's user avatar
2 votes
1 answer
24 views

How to subset a melt object

My issue I have melt object from reshape2 library. I would like to subset variables with value==1. However, when I select value from subset melt object, I get the id instead of variable. How to get a ...
Yacine Hajji's user avatar
  • 1,307
1 vote
1 answer
56 views

Reshape Pandas Dataframe and group by 2 level columns

I have a dataframe with flat structure of having unique Rows as follow. I need to reshape it as shown below. Using Pivot table and swapping levels, I managed to obtain somewhat closer to the result, ...
rush dee's user avatar
  • 336
0 votes
1 answer
21 views

Troubleshooting onnxruntime inference - X num_dims does not match W num_dims

Using the nnhash.py script found here: https://github.com/AsuharietYgvar/AppleNeuralHash2ONNX # Copyright 2021 Asuhariet Ygvar # # Licensed under the Apache License, Version 2.0 (the "License&...
Joshua Terrill's user avatar
0 votes
1 answer
46 views

this code show an reshape error. how fix this?

I'm new in python and ML. I wrote this code for practicing. It displays this error. how do I solve this reshape problem? import pandas as pd import sklearn as skl data=pd.read_csv('housing.csv') ...
Vahid Agha ahmadi's user avatar
2 votes
3 answers
74 views

Converting dataframe from "wide" to "long" format with pairs of ID variables

Here's an example of what I am trying to do. I am starting with a dataframe in "wide" format, like below. #sample dataframe id_1 <- c(260, 500, 640, 720) id_2 <- c(261, 501, 641, 721) ...
wooden05's user avatar
  • 195
0 votes
1 answer
90 views

How to reshape (n,) array to (n,3) array? [closed]

I have an array with (n,) dimension and for a project I need to have this array with (n,3) shape. This array is a set of a 3-dimensional points. This is the code : vertices = np.array([line[7:] for ...
Margot Berranger's user avatar
0 votes
0 answers
40 views

Performance of numpy matrix vector product on scipy.stats.qmc.Sobol vector when changing reshaping order

Solution at the bottom. I am trying to implement a Brownian bridge and want to speed up the path construction via numpy matrix multiplication, once the bridge is initialised. I am drawing data for 3 ...
Severin's user avatar
0 votes
1 answer
36 views

Reshape seems to be losing observations

i am using reshape in dplyr to turn a long data table into a wide one. but when i do, i seem to be losing some observations. the data table called "data" is a record of 6 different species ...
colby tanner's user avatar
0 votes
1 answer
59 views

How to divide a 2-D tensors into smaller blocks using pytorch?

I've downloaded the EMNIST dataset of letters, and I've converted each image to a torch.tensor object with shape torch.size([28, 28]). However, I would like divide the 28*28 image into 7*7 blocks, ...
Chenming Zhang's user avatar
0 votes
0 answers
48 views

Pandas move levels of a composite column as a value

Let's imagine as a starting point I have a dataframe, similar to the one below (using a tuple for the composite columns): Index, (ATop,AMiddle,ABottom,filt1_1, filt2_1), (ATop,AMiddle,ABottom,filt1_2,...
georgi koyrushki's user avatar
0 votes
0 answers
89 views

reshape a tensor in firebase cloud functions

Im working on a machine learning project and since I don't know the amount of categories in the dependend variables I don't want to hardcode it. In my project now I have 3 different categories but I ...
chrispsv's user avatar
  • 655
3 votes
3 answers
84 views

Convert vector to matrix by blocks -reshape

just a quick question I am struggling in R to convert a list of numbers to a matrix that has a fixed number of rows and the numbers are placed in triplets (blocks of 3 rows) at a time The elements are ...
chriliv's user avatar
  • 33
0 votes
3 answers
46 views

How can I add a dimension to Torch tensor with values of first two dimensions repeated in the new dimension

I have a Tensor of shape [a,b]. How can I reshape it to [a,b,c] such that all the values along the new dimensions repeat values of the i,j entry of the original tensor of shape [a,b]? ex: a = 2, b= 3 ...
Lrom's user avatar
  • 13
0 votes
2 answers
40 views

pivot_longer with multiple columns with different column name patterns and count column [duplicate]

I have looked at multiple posts but have not seen this exact situation addressed. The linked examples have more consistent variable names (not single/multiple underscores) and do not add the count ...
Agnes Flack's user avatar
-1 votes
1 answer
56 views

Numpy reshape() to display 2D array in 3D programmatically

Example Data I have an array of weather data by lat/lon in the following shape: (1038240,4) (See photo for sample example data) I want to reshape this to the shape (4,721,1440) which would be four ...
Declan's user avatar
  • 3
0 votes
0 answers
18 views

how to build a vae without reshape error?

I build a VAE following https://blog.tensorflow.org/2019/03/variational-autoencoders-with.html PROBLEM: I thick the problem is in the decoder when I want to reshape the latent Distribution i face this ...
mmd-ghamgosar's user avatar
1 vote
1 answer
26 views

Converting two 2d arrays of different shapes into a 3d array

How to convert two 2d arrays of shapes (629, 5) and (629, 6) into a 3d array of shape (629, 5, 6)? Input: [[2, 5, 6, 7, 8], [3, 5, 6, 7, 8], [4, 5, 6, 7, 8]] [[2, 5, 6, 7, 8, 9], [3, 5, 6, 7, 8, 9]...
Rebel's user avatar
  • 495
0 votes
1 answer
42 views

cannot reshape array of size 4 into shape (4,4) in DataFrame where clause

Can anyone explain to me what is going on? Here's the piece of code. If I have the DataFrame of precisely length 4, the statement in the try clause throws an exception. If I make the dataframe of any ...
user23873134's user avatar
1 vote
1 answer
32 views

Given a few block matrices, get the overall large matrix

In short, we are given a 4D tensor y of shape ( B // s2, D2 // s1, s1, s2), where y[i,j,...] represents a matrix of shape (s1,s2). These are the block matrices used to construct the overall large ...
Goldenalcheese's user avatar
0 votes
1 answer
60 views

Keep all matched rows when reshaping from long to wide

I am trying to reshape my data from long to wide format. I would like to keep all rows that match for sn3=1 and sn3=2 instead of taking only the first value. How can I achieve this? Desired output: ...
Victoria's user avatar
0 votes
0 answers
20 views

wide data with part of column name as value [duplicate]

I have the following data structure in R DE_GDP DE_INFL US_GDP US_INFL 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 ...
Rkid's user avatar
  • 33
0 votes
3 answers
47 views

calculate annual cases after reshaping dataframe in R

I am working in R and I want to calculate the last column Annual_Cases based on the available years for each surgeon. The variable Years was reported per each 3-year time interval. Some surgeons were ...
Mohamed Rahouma's user avatar
0 votes
3 answers
72 views

How to append value of every two columns in R?

go from m <- matrix(1:16, nrow = 4) [,1] [,2] [,3] [,4] [1,] 1 5 9 13 [2,] 2 6 10 14 [3,] 3 7 11 15 [4,] 4 8 12 16 to 1x16 matrix 1 5 2 6 3 7 4 8 9 ...
dunbesscolder's user avatar
0 votes
0 answers
43 views

Is there a more effective way to create new columns from row values in a Pandas DataFrame? [duplicate]

Given a dataframe with three initial columns, one of which has categorical type with two categories, the aim is to create distinct columns for each category and subsequently store within them the ...
ciranzo's user avatar
  • 57
0 votes
0 answers
13 views

Reshape LSTM Layer Input Tensorformat

I have a table with 4700 rows and 50 columns. The last 3 columns should be predicted. How do I have to set up my X and my y to be able to enter it in an LSTM layer? X = (?, ?, ?) y = (?, ?) I ...
Jumpstar's user avatar
0 votes
0 answers
16 views

How do I reshape the pythonarrays as input and output for a convolutional neural network in Keras4Delphi properly

I'm working on a Speech2Vec algorithm with 3 neural networks. The first of these networks is for speech recognization. It converts a single FFT window (one dimensional) to 'sound nrs.': 1..1500. So I ...
RoelsRule's user avatar
4 votes
3 answers
107 views

Sum up replicate columns in dataframe, keep rows unique

I thought this would be a relatively easy task to do but I couldn't find examples here that weren't focused on summing up rows based on column conditions. What I'm trying to achieve is to sum up ...
Katherine Chau's user avatar
1 vote
2 answers
72 views

R - Reshape list with matrices

I am working with a list of matrices that was created from the output of combn: lapply(2:length(c("A","B","C","D","E")), function(n) combn(c("A&...
thiagoveloso's user avatar
  • 2,671
2 votes
1 answer
49 views

Pivoting dataset to long format for all variable pairs following specific name pattern

I've got data from an experiment with 2 conditions where each participant got tested in both conditions for various properties. The dataset is in wide format, the variable name pattern is like this: ...
Madamadam's user avatar
  • 918
1 vote
1 answer
67 views

Compute row sums and column sums efficiently in Julia

Consider the code below test_vector = 1:100 group_size = 10 num_groups = div(length(test_vector), group_size) res_1 = sum(reshape(test_vector, group_size, num_groups), dims=1) res_2 = sum(reshape(...
user1691278's user avatar
  • 1,845
5 votes
3 answers
218 views

merge groups of columns in a polars dataframe to single columns

I have a polars dataframe with columns a_0, a_1, a_2, b_0, b_1, b_2. I want to convert it to a longer and thinner dataframe (3 x rows, but just 2 columns a and b), so that a contains a_0[0], a_1[0], ...
DeltaIV's user avatar
  • 5,539
1 vote
2 answers
35 views

R : Reshape Long => wide with different value length

I want to reshape from long to wide the following data base df_long <- data.frame( indiv_id = c(rep(1,2), rep(2,6), rep(3,4)), value = c(sample(x = 2), sample(x = 6), sample(x = 4)), field_id ...
Jamman's user avatar
  • 11
-2 votes
1 answer
113 views

How to disable ReSharper but keep dotTrace and dotMemory available in VS2022?

I want to run dotTrace and dotMemory from Visual Studio 2022. I do not want ReSharper in any form or shape. Is there a way to achieve this? Please note - this question is about how to start dotTrace/...
Boppity Bop's user avatar
  • 10.3k
0 votes
0 answers
35 views

Rowwise comparison in R for several fields [duplicate]

Suppose you have a dataframe df_matches with transaction data structured in the following way: | REPORT_ID| VALUE | SIDE | COUNTRY | CP1 | CP2 |... | -------- | -------- | -------- | ...
Marius's user avatar
  • 3
0 votes
1 answer
93 views

reshape dataframe based on event occurance and clearing

i want to see if there is an efficient way to reshape dataframe that is read from a tab separated csv file. the data consist of event codes and messages that are stacked up vertically with their ...
Hannibal's user avatar
  • 105
0 votes
0 answers
24 views

how dcast melted data winto a table with header and sub-header?

I have Input data like the one below and I want to know if there is any way to reshape it into an Excel format with a header and sub-header. Input: Cons rep name value 10 N=1 A 12 ...
star's user avatar
  • 765
0 votes
1 answer
81 views

Long to wide in Python or SQL with all possible data combinations in columns

Input format: CUSTOMER MONTH ISSUE 1 M1 ABC 1 M1 DEF 1 M2 ABC 1 M3 QRS 2 M1 PQR 2 M2 PQR 2 M2 ABC 2 M3 DEF Desired output format: CUSTOMER M1 M2 M3 1 ABC ABC QRS 1 ...
Anjana's user avatar
  • 3
0 votes
0 answers
15 views

Shape issues in Training a Keras Model

Here is the code that I have written: Df_input = df_close[input_col] df_Output = df_close[Output_cols] def preprocess_multistep_lstm(Input_Sequence, Output_Sequence, n_steps_in, n_steps_out, features, ...
Jaffer Wilson's user avatar
3 votes
3 answers
96 views

Is it possible to reorder a table in R?

I have a table as belowe: dput(df) structure(list(Samples = c("Cont-4", "Cont-4", "Cont-4", "Cont-4", "Cont-4", "Cont-4", "Cont-4"...
A.Mokhtari's user avatar
4 votes
2 answers
116 views

How to reference the last column in pivot_longer() without naming it or providing the index number?

I'm writing a function to pivot a data table to long format. For the cols = argument, the name of the first column will always be the same, but the final column (and number of columns) will change. ...
ksinva's user avatar
  • 361
1 vote
1 answer
121 views

Convert data from wide to long format by checking the values of a row

I have the data below data<-structure(list(id = c("R_88j7lG37gLfxk22", "R_6DK8lERVf8lSQf4" ), t1_choice = c("2", "3"), t2_choice = c("1", "3&...
firmo23's user avatar
  • 8,306
0 votes
0 answers
15 views

Is there any xarray code for selecting data in the shape of a parallelogram?

I have a temperature data with dimensions YC and XC. I'm interested in selecting data within the red parallelogram shape depicted in the figure. xarray.DataArray'YC: 720 XC: 560. However, when using ...
Pragnya Makar's user avatar
0 votes
1 answer
165 views

numpy reshape implementation

My main focus will on this page. First, I don't understand the page. For the first parameter shape, ndarray.reshape(shape, order='C') why this method on ndarray allows the elements of the shape ...
JJ.'s user avatar
  • 113
0 votes
0 answers
17 views

Received a label value of 3 which is outside the valid range of [0, 2)

# Consider increasing epochs for better performance import numpy as np X = np.array(X,dtype='float64') y = np.array(y, dtype ='float64') model.fit(X, y,epochs=10) test_loss, test_acc = model.evaluate(...
Raed Althabti's user avatar

15 30 50 per page
1
2 3 4 5
79