I\'ve got a multidimensional numpy array that I\'m trying to stick into a pandas data frame. I\'d like to flatten the array, and create a pandas index that reflects the pre-
def ndarray_to_indexed_2d(data): idx = np.column_stack(np.unravel_index(np.arange(np.product(data.shape[:-1])), data.shape[:-1])) data2d = np.hstack((idx, data.reshape(np.product(data.shape[:-1]), data.shape[-1]))) return data2d