Why is taking the transpose here?

In the labs, when the images from random training examples are drawn the vector X that contains the pixel intensities is converted into a matrix. However, I don’t understand why we have to take the transpose of the matrix. Here is an example of the code that appear in the labs:

import warnings
warnings.simplefilter(action=‘ignore’, category=FutureWarning)

You do not need to modify anything in this cell

m, n = X.shape

fig, axes = plt.subplots(8,8, figsize=(5,5))
fig.tight_layout(pad=0.13,rect=[0, 0.03, 1, 0.91]) #[left, bottom, right, top]
for i,ax in enumerate(axes.flat):
# Select random indices
random_index = np.random.randint(m)

# Select rows corresponding to the random indices and
# reshape the image
X_random_reshaped = X[random_index].reshape((20,20)).T

# Display the image
ax.imshow(X_random_reshaped, cmap='gray')

# Predict using the Neural Network
prediction = model.predict(X[random_index].reshape(1,400))
prediction_p = tf.nn.softmax(prediction)
yhat = np.argmax(prediction_p)

# Display the label above the image
fig.suptitle("Label, yhat", fontsize=14)

What I’m asking is about the transpose in the line ’ X_random_reshaped = X[random_index].reshape((20,20)).T’.

Hi @Marcos_Quintas_Perez
Welcome to the community!

We did transpose because if we didn’t it the the image appears round like this image
so to get the correct pixes in correct places to appear the image in right place we done transpose for pixels

Best Regards,

yeah I’ve already understood that. What I’m asking is why it’s in that way.

Hello @Marcos_Quintas_Perez,

I think it’s just because the data provided was pre-transposed previously, and so we have to transpose it back here. However, I think there is no special reason for why we have to pre-transpose it for this assignment.