Reputation: 150
I have a dataframe, where each row describe a matrix (3,3):
I transformed this dataframe in multiple matrices, to do some matrices operations with them. I used the code:
df.to_numpy().reshape(-1,3,3)
Which returned:
This is exactly what I wanted but, after finished the operations with the matrices, I need to transform all of these matrices in the original form of the dataframe, like in the first image. How can I do this?
There's some analogue function to .to_numpy()
? I tried pd.DataFrame(array)
but don't worked.
d = pd.DataFrame(array)
ValueError: Must pass 2-d input
Upvotes: 0
Views: 69
Reputation: 18141
Try:
array_2d = array.reshape((-1, 9))
d = pd.DataFrame(array_2d)
Upvotes: 1