I got some problems while reading the files int the step:
def parse_data_from_input(filename):
for every file I read into labels:
labels = np.genfromtxt( file, delimiter=‘,’, skip_header=1,usecols=(0,))
and that works fine and I get the correct dimensions in the next function checking the code
it also works with np.loadtxt()
then I do the same for images, I tried either with np.genformtx() and with np.loadtxt() but I get an error the the file is now empty
error for loadtxt version:
/usr/local/lib/python3.10/dist-packages/numpy/lib/npyio.py in loadtxt(fname, dtype, comments, delimiter, converters, skiprows, usecols, unpack, ndmin, encoding, max_rows, like)
1079 # Skip the first skiprows
lines
1080 for i in range(skiprows):
→ 1081 next(line_iter)
1082
1083 # Read until we find a line with some values, and use it to determine
StopIteration:
##################################################################
error for genfromtxt() version:
:27: UserWarning: genfromtxt: Empty input file: “<_io.TextIOWrapper name=‘./sign_mnist_train.csv’ mode=‘r’ encoding=‘UTF-8’>”
images = np.genfromtxt(
Hello @Peter_Grabner ,
Welcome to the community!!
Send me your notebook via dm such that I can check where it went wrong. By clicking on the profile picture, you will see an option to message. There you can attach your notebook. Then we can discuss the issues here.
With regards,
Nilosree Sengupta
[NOTEBOOK REMOVED BY MENTOR AS PER COMMUNITY GUIDELINES]
So here is my notebook
As I had to make a copy I rerun the scripts, the error message is now gone, but you can see in the output that the shape of images in (0,)
Hello @Peter_Grabner ,
Don’t post notebook publicly here.
I had said :
Now let’s get into your code.
There are several issues in your code. I am listing them :
-
#Hint : Use csv.reader, passing in the appropriate delimiter
U need to use csv.reader
But you used genfromtxt. I understand that the genfromtxt function tends to be generally faster than using the csv module for reading large CSV files.
But, the csv module is more flexible and can handle more complex CSV files.
-
#Hint : Remember that csv.reader can be iterated and returns one line in each iteration
So there will be iterations to extract data for labels & images. But in your code no iterations.
-
You are reading data twice of labels and images. But you need to read once only for label, then from there, with further steps get images.
-
There would be certain more corrections. As a mentor, I cannot tell line by line. But you will able to understand it, when you will read a couple times the hints, slowly, you will get more clarity.
Hope this helps.
With regards,
Nilosree Sengupta
Hello,
so now I understand the issue I had. It is the way python implements the file object. Every function using it gets the same object (or h handle or pointer to it which is iterating over the lines till the end of the file.
If you use
print(file) => first row e.g. line
print(file) => second row
…
My solution is to use np.genfromtxt() and then copy the first column to labels and after that copy everything except the first column to images.
RGDS Peter
Hello @Peter_Grabner ,
The grader works based on whatever asked to do as per the hints given.
With regards,
Nilosree Sengupta
Hello @Peter_Grabner ,
You’re welcome!
Happy learning.
With regards,
Nilosree Sengupta