My code (see attached) seems to be parsing the CSV file correctly. I have a feeling though that there should a shorter/more efficient way to achieve the same result, perhaps without the for-loop.
I would appreciate any tips.
[snippet deleted by mentor]
You don’t need a for loop once you have read content using np.loadtxt
. Use array slicing to extract columns from data read from the file.
On a related note, a single call to np.loadtxt
is sufficient.
Thanks, Balaji! Should the slicing be somehow wrapped around the np.loadtxt (as it returns an ndarray)? The np.loadtxt() with the parameters I set returns:
Training images has shape: (27455, 784) and dtype: float64
Training labels has shape: (27455,) and dtype: float64
Validation images has shape: (7172, 784) and dtype: float64
Validation labels has shape: (7172,) and dtype: float64
That’s why I resorted, for a lack of a better solution, to the for-loop in order to slice the 784-dimensional vector into a 28x28 matrix.