'How can I convert pandas dataframe to tensor and reshape it?

I'd like to change some dataframe to tensor to make it work on rnn model. The original shape of data is like this.

input : X_train.shape
output : (2101, 32)

and the expected shape is

output : (2101, 4, 8)

I've tried

X_train.to_numpy.reshape(-1, 4, 8)

but it did not work.

plz help



Solution 1:[1]

You're looking for the numpy method:

X_train.reshape(-1, 4, 8).numpy()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 iacob