probably simple, reverse a reshape...
Hello, this is probably one of those questions that is going to seem simple after reading responses... I'm trying to get the original array indices out of a row number from a reshaped array... shouldn't this be possible somehow? import numpy as np a = np.ones((3,5,10)) #for testing, I've done the following: a[0,:,:5] = np.eye(5,5)*1 a[1,:,:5] = np.eye(5,5)*10 a[2,:,:5] = np.eye(5,5)*20 #Ok, so I reshape the array: b = a.reshape(15,10) #now I want to be able to 'back out' the original shape indices from the row number of the new array. #I thought I could do something like this: d0,d1,d2 = a.shape new_d0 = row/d1 new_d1 = row/d0 #But it doesn't quite work... any suggestions as to what I am missing? -- View this message in context: http://www.nabble.com/probably-simple%2C-reverse-a-reshape...-tp22171584p221... Sent from the Numpy-discussion mailing list archive at Nabble.com.
John [H2O] wrote:
Hello, this is probably one of those questions that is going to seem simple after reading responses...
and a few more minutes of thinking: def row2shape(row,a): """ to get indices a 2d array row# to the 3d array from which it was reshaped. "" d0,d1,d2 = a.shape; nd0 = row/d1; nd1 = (row-(nd0*d1)); return nd0,nd1 -- View this message in context: http://www.nabble.com/probably-simple%2C-reverse-a-reshape...-tp22171584p221... Sent from the Numpy-discussion mailing list archive at Nabble.com.
participants (1)
-
John [H2O]