title: Why does my pycharm code give "list index out of range" ? I'm following the youtuber
body: <p>I'm doing a face-recognition code, at first I followed the <a href="https://www.youtube.com/watch?v=sz25xxF_AVE&amp;list=WL&amp;index=10&amp;t=2228s" rel="nofollow noreferrer">youtube video</a> done by Murtaza and it worked but when I tried to do it by my own I fell in that problem and couldn't solve it yet, Here is the code:</p>
  <pre><code>while True:
      success, img = webcam.read()
      imgS = cv2.resize(img, (0, 0), None, 0.25, 0.25)
      imgS = cv2.cvtColor(imgS, cv2.COLOR_BGR2RGB)
      imgSLocs = face_recognition.face_locations(imgS)
      imgSEncodes = face_recognition.face_encodings(imgS, imgSLocs)
  
  for encode, loc in zip(imgSEncodes, imgSLocs):
      compare = face_recognition.compare_faces(refEncodes, encode)
      faceDist = face_recognition.face_distance(refEncodes, encode)
      print(faceDist)
      matchindex = np.argmin(faceDist)
      print (matchindex)
      if compare[matchindex]:   # in this line the error starts &lt;------------
          name = refImgNames[matchindex].upper()
          print(name)
  </code></pre>
  <p>What I expect is matchindex = 0 or 1 because I only have two images, but what happens is that <code>matchindex = np.argmin(faceDist)</code> has almost no effect on the code, shouldn't it give me the index of least value in these values?
  Notes that might be useful: <code>faceDist</code> is a compound array that has probably 128 values inside index 0 and 128 values inside index 1.
  I'm new at python codes so please consider the probability of basic mistakes.
  here's the whole code if it can help:</p>
  <pre><code>import cv2
  import numpy as np
  import face_recognition
  import os
  
  path = 'refrence images'
  imgList = os.listdir(f'{path}')
  refImgs = []
  refImgNames = []
  print(imgList)
  for i in imgList:
      image = cv2.imread(f'{path}/{i}')
      image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
      refImgs.append(image)
  
  
  def imgEncoder(images):
      encodes = []
      for i in images:
          imgloc = face_recognition.face_locations(i)
          imgencode = face_recognition.face_encodings(i, imgloc)
          encodes.append(imgencode)
      return encodes
  
  
  refEncodes = imgEncoder(refImgs)
  print('encoding done Alhamdulillah')
  webcam = cv2.VideoCapture(0)
  
  while True:
      success, img = webcam.read()
      imgS = cv2.resize(img, (0, 0), None, 0.25, 0.25)
      imgS = cv2.cvtColor(imgS, cv2.COLOR_BGR2RGB)
      imgSLocs = face_recognition.face_locations(imgS)
      imgSEncodes = face_recognition.face_encodings(imgS, imgSLocs)
  
      for encode, loc in zip(imgSEncodes, imgSLocs):
          compare = face_recognition.compare_faces(refEncodes, encode)
          faceDist = face_recognition.face_distance(refEncodes, encode)
          print(faceDist)
          matchindex = np.argmin(faceDist)
          print (matchindex)
          if compare[matchindex]:   # in this line the error starts
              name = refImgNames[matchindex].upper()
              print(name)
              y1, x2, y2, x1 = loc
              y1, x2, y2, x1 = y1 * 4, x2 * 4, y2 * 4, x1 * 4
              cv2.rectangle(img, (x1, y1), (x2, y2), (0.255, 0), 2)
              cv2.rectangle(img, (x1, y2 - 35), (x2, y2), (255.255, 0), cv2.FILLED)
              cv2.putText(img, name, (x1 + 6, y2 - 6), cv2.FONT_HERSHEY_COMPLEX_SMALL, 1, (255, 255, 255), 1)
              cv2.imshow(1,img)
              cv2.waitKey(0)
      print('done')
  </code></pre>
  <p><a href="https://i.stack.imgur.com/pdfc9.png" rel="nofollow noreferrer">you can see on left panel that I only have 2 images (1.png, 2.png)</a></p>