title: Read 3D array (images) with csv.reader
body: <p>As part of an online course, I have to create a function that reads a large set of image data using csv (not allowed to use pandas) and outputs the images and their labels in the correct format, as numpy array floats. </p>
  
  <p>I will try to make a short example here: </p>
  
  <pre><code>&gt; raw_data = 0 0 0 0 0 0 0 0 0 0
  &gt;            L1,1,2,3,4,5,6,7,8,9
  &gt;            L2,4,5,6,7,8,9,1,2,3
  &gt;            .....................
  &gt;            L20 9,8,7,6,5,4,3,2,1
  &gt; 
  &gt;  output1 = [L1, L2 .... L20] 
  &gt;  output2 = [1.0,2.0,3.0         (for a single row)
  &gt;            4.0,5.0,6.0
  &gt;            7.0,8.0,9.0] 
  &gt;  output1.shape = 20 
  &gt;  output2.shape= 20, 3, 3
  </code></pre>
  
  <p>First row should be ignored (it is the column names). 
  Each row consists of 10 values, representing the 9 pixels of the given image, + the first column of each row which is the label for the respective image. 
  After I read the images and the labels, I have to convert them to float values and reshape each 9 pixel row into a 3x3 matrix.</p>
  
  <p>For example if the original data set has 20 rows (minus the first row), the two outputs of the function should have a shape of (20, 3, 3) and (20) - i.e. 20 3x3 images, and an array of 20 labels. </p>
  
  <p>I never used the csv reader and with open before, so I'm struggling. 
  This is what I have so far (this is the original code for the original data set, which is much larger than the example I gave). </p>
  
  <blockquote>
    <p></p>
  </blockquote>
  
  <pre><code>with open(filename) as file:
           file = csv.reader(file, delimiter = ',')   
           for row in file:
               images = row[1:785]
               labels = row[0]
           labels = np.array(labels).astype('float')
           images = np.array(images).astype('float')
           images = np.array(np.split(images, 28))  
           print('label:', labels.shape)
           print('image:', images.shape)
  return images, labels
  </code></pre>
  
  <p>In the end, the shapes I am getting are 
  (3,3) for the images - hence only the first row has been read; 
  () for the labels - hence, empty. </p>
  
  <p>When I tried to put the array conversion inside the for loop, it refuses to convert the str into float, I get an error. </p>
  
  <blockquote>
    <p>Value error: Can not convert string to float</p>
  </blockquote>