I am having some challenges getting my function to work properly. When testing the function it seems to get caught in a loop since no output is displayed. I would appreciate any suggestions or recommendations. I know I may have to address the dimensions of the images array but I’m hoping to at least get the following code to run:
def parse_data_from_input(filename):
with open(filename) as file:
csv_reader = csv.reader(file, delimiter=',')
next(csv_reader)
label_list = []
image_list = []
for row in csv_reader:
label_list.append(row[0])
labels = np.asarray(label_list, dtype =np.float64)
image_list.append(row[1:])
images = np.asarray(image_list, dtype=np.float64)
return images, labels
I found using the csv.reader() method to be incredibly slow. It took longer to do than the models to train from week 3.
What I did in the end was use numpy’s loadtxt() method, and then split the arrays into the correct shapes. I managed to load the data that way in 22 seconds, which was much faster than the 10 minutes I waited until I gave up with csv.reader().
Thanks canwaf, I’ll have to give loadtext()method a try.
I was able to sort out the issue with the code, I removed the np.asarray() lines from the for loop and that seemed to fix the issue. I performed the conversion to an array from a list outside of the loop and it the code worked fine.
You could sir but I recommend to not change the code that’s already written in the notebook
It might affect your grading
Thanks and Regards,
Mayank Ghogale