Help with parse_data_from_input() Function

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.

Hope that helps anyone with a similar issue.

can you help me, how is it going to be?

@Yohan_Kristian_M7011 what issue are you facing sir ?
What do you need help with sir?
Thanks

Can i use pandas instead, it just 3 line of code

  df = pd.read_csv(filename)
  labels = np.array(df.label).astype(np.float64)

  images = df.drop(columns=['label']).astype(np.float64).reshap(-1, 28, 28)

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