reshape

Reshape a numpy array so the columns wrap below the original rows

Reshape a numpy array so the columns wrap below the original rows Question: Consider the following scenario: a = np.array([[1,1,1,3,3,3], [2,2,2,4,4,4]]) np.reshape(a, (4, 3)) Output: array([[1, 1, 1], [3, 3, 3], [2, 2, 2], [4, 4, 4]]) Desired output: array([[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4]]) How can I reshape …

Total answers: 2

How to understand B=np.reshape(A, (a, a, b)) and reverse back by B[:,:,1]

How to understand B=np.reshape(A, (a, a, b)) and reverse back by B[:,:,1] Question: I am quite confused about the following import numpy as np A = np.array([[1,2,3], [2,3,4], [3,4,5]]) A is a 3×3 matrix obviously. Now consider B = np.reshape(A, (3, 3, 1)) B is array([[[1], [2], [3]], [[2], [3], [4]], [[3], [4], [5]]]) If …

Total answers: 1

I have to pass multiple columns to the one aggregate function

I have to pass multiple columns to the one aggregate function Question: I have a very huge, but simple 2D dataframe, and I have to reshape it to the following (no need to look into data, just shape. Data processing and filtering are already implemented in some functions. Indexes are taken from time_spend_company column) max …

Total answers: 1

Reshape dataframe from long to wide

Reshape dataframe from long to wide Question: my df: d = {‘project_id’: [19,20,19,20,19,20], ‘task_id’: [11,22,11,22,11,22], "task": ["task_1","task_1","task_1","task_1","task_1","task_1"], "username": ["tom","jery","tom","jery","tom","jery"], "image_id":[101,202,303,404,505,606], "frame":[0,0,9,8,11,11], "label":[‘foo’,’foo’,’bar’,’xyz’,’bar’,’bar’]} df = pd.DataFrame(data=d) So my df, is long format, in some duplicate and only image_id is unique. I trying pivot my df, with pd.pivot and pd.merge reshape to wide format by username. My …

Total answers: 1

RGGB (x,y) –> RGB = (x/2,y/2,3)

RGGB (x,y) –> RGB = (x/2,y/2,3) Question: The output of a camerasensor is SRGGB12. import numpy as np rggb = np.array([[‘R’, ‘G’, ‘R’, ‘G’], [‘G’, ‘B’, ‘G’, ‘B’], [‘R’, ‘G’, ‘R’, ‘G’], [‘G’, ‘B’, ‘G’, ‘B’]]) test2 = np.chararray((3, 4, 4)) test2[:] = ” test2[2,::2, ::2] = rggb[1::2, 1::2] # blue test2[1,1::2, ::2] = rggb[0::2, …

Total answers: 2

Reordering DataFrame in Pandas

Reordering DataFrame in Pandas Question: I have a DataFrame that looks like this: A B C D E 1 a a a a a 2 b b b b b 3 c c c c c 4 d d d d d 5 e e e e e 6 f f f f f Anyone …

Total answers: 1

Divide an array into smaller arrays, square matrix

Divide an array into smaller arrays, square matrix Question: I am trying to reshape a matrix, but I am struggling to make reshape work Lets say that I have a (6×6) matrix (A), and we want to divide it in 4 arrays (A1,A2,A3,A4). For example A=[[ 1 2 3 4 5 6] [ 7 8 …

Total answers: 1

reshape not require to display mnist images?

reshape not require to display mnist images? Question: If I want to display one image from mnist dataset, I need to reshape it from (1,28,28) to (28,28) using the following code: import tensorflow as tf import matplotlib.pyplot as plt mnist = tf.keras.datasets.mnist (x_train, y_train), (x_test, y_test) = mnist.load_data() x_train, x_test = x_train / 255.0, x_test …

Total answers: 1

Reshaping a dataframe every nth column

Reshaping a dataframe every nth column Question: I have two datasets. After merging them horzontally, and sorting the columns with the following code, I get the dataset below: df= X Y 5.2 6.5 3.3 7.6 df_year= X Y 2014 2014 2015 2015 df_all_cols = pd.concat([df, df_year], axis = 1) sorted_columns = sorted(df_all_cols.columns) df_all_cols_sort = df_all_cols[sorted_columns] …

Total answers: 1