Numpy reshape and Keras

37 views
Skip to first unread message

Denis Dal Soler

unread,
Oct 29, 2024, 10:21:07 AM10/29/24
to Keras-users
Hi,
I'm new in this group.
Can someone explain me this sentence code used in a LSTM algorythm please?
x_train is a matrix (n row, m column).
Thanks
Denis

x_train = np.reshape(x_train, (x_train.shape[0], x_train.shape[1], 1))

Samer Attrah

unread,
Oct 29, 2024, 8:29:41 PM10/29/24
to Keras-users
Hello,
Welcome to the group
this sentence will reshape the matrix x_train from the shape (n row, m column) to (n row, m column, 1) 
and this transformation is necessary in many cases such as processing the x_train matrix as an image which has an unknown depth in the first case and it is a greyscale image in the second case after reshaping.

I hope that helps.

Kind regards
Samer

Denis Dal Soler

unread,
Nov 1, 2024, 4:41:50 PM11/1/24
to Samer Attrah, Keras-users
Thank Samer for your reply.
That I don't understand is the final format of ×_train.  Meanwhile it is clear that initially x_train is a nxm matrix of real value I can't figure out the x_train after reshape.
 Thanks


--
You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/keras-users/0fd36b77-0de8-40e5-9c39-028a80db6fc7n%40googlegroups.com.

Lance Norskog

unread,
Nov 1, 2024, 6:37:49 PM11/1/24
to Denis Dal Soler, Samer Attrah, Keras-users
It is a 3-dimensional matrix of n x m x 1. If it was RGB, it would be n x m x 3.



--
Lance Norskog
lance....@gmail.com
Redwood City, CA
Reply all
Reply to author
Forward
0 new messages