Why is Array rotated and flipped?

Hi I am new to Julia, I mostly use Python, so if someone could tell me what I did wrong that would be great.

using PyPlot
using DataFrames
using CSV

train = CSV.read("mnist_train.csv", datarow=1)
train_labels = train[1]
train = train[2:end]

println("Label: ", train_labels[3])
imshow(reshape(convert(Array, train[3, :]), (28,28)), "gray")

Julia returns

%matplotlib inline

import pandas as pd
import matplotlib.pyplot as plt

train = pd.read_csv('mnist_train.csv', header=None)
plt.imshow(train.iloc[2, 1:].values.reshape((28,28)), cmap='gray')
print(f'Label: {train.iloc[2,0]}')

Python returns

It looks like your data are stored linearly and you reshape them into a 28x28 matrix. Python performs this operation row-major — that is, it fills each row sequentially. Julia is column major, so it fills each column sequentially. The two are transposes of each other. You can use permutedims to convert between the two.


I originally tried

train = DataFrame(transpose(convert(Array, train[2:end])))

to access them columnwise but that didn’t work.