title: Store arrays in unique variables at each for loop iteration in python
body: <p>Currently i am working on a python project using windows platform in which i need to deal with images.
  Under this, i need to divide my image into several segments and then store them as unique images.
  For this, i need to convert my image into floating point array which would then be segmented
  The segmentation part is sorted.
  But the point where i am stuck is storing of these newly generated arrays.</p>
  
  <p>For example if my loop runs for 6 times, 6 new arrays would be generated (of large size say 300 X 420) and i need to store them in unique variables for each iteration such that they do not overlap each other.</p>
  
  <p>How do i do that?</p>
  
  <p>How can i store newly generated arrays of my loop into different arrays for each iteration? I need these arrays afterwards so it is important for me to store them.</p>
  
  <p>The number of arrays generated would be dynamic too! </p>
  
  <p>this is the code:</p>
  
  <p>`</p>
  
  <pre><code>#read image and do its segmentation
   image = cv2.imread("Path to input image\\___.png")
   segments = slic(img_as_float(image), compactness=100.0, n_segments = 2,sigma = 5) 
   #loop to generate individual segments and to store them individually
   for (i, segVal) in enumerate(np.unique(segments)):
      print "[x] inspecting segment %d" % (i)
      mask = np.zeros(image.shape[:2], dtype = "uint8")
      mask[segments == segVal] = 255
      s2 = np.array(segments);
      bb= (cv2.bitwise_and(image, image, mask = mask) )
      #above the unique array is generated
      #store the generated array as unique image at desired location
      cv2.imwrite('Path to store\\__.png', bb)
  </code></pre>
  
  <p>`</p>
  
  <p>NOTE: the arrays generated are already 2-D and of the size 327 X 500.
  So please give me a solution to store 2-D arrays.
  It does now matter what we use dictionary, list or new variables :)</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>As per some solutions, i tried to insert the newly generated arrays into another big array. But still there are some errors which i am getting. The new code chunk is:</p>
  
  <pre><code>#read image and do its segmentation
   image = cv2.imread("Path to input image\\___.png")
   segments = slic(img_as_float(image), compactness=100.0, n_segments = 2,sigma = 5) 
   #loop to generate individual segments and to store them individually
   for (i, segVal) in enumerate(np.unique(segments)):
      print "[x] inspecting segment %d" % (i)
      mask = np.zeros(image.shape[:2], dtype = "uint8")
      mask[segments == segVal] = 255
      s2 = np.array(segments);
      results= []
      bb= (cv2.bitwise_and(image, image, mask = mask) )
      results.append(bb)
      #above the unique array is generated and appended into a big array
      #store the generated array as unique image at desired location
      cv2.imwrite('Path to store\\__.png', results(i))
  </code></pre>
  
  <p>The errors which i am getting are:</p>
  
  <p>list object is not callable for this line <code>cv2.imwrite('Path to store\\__.png', results(i))</code></p>
  
  <p>What changes shall be done?</p>