title: How can i show an image with matplotlib?
body: <p>I am trying to import some images into python to train a ML Algorithm. Unfortunately when i try to show them, an erro occurs:</p>
  <pre><code>TypeError: Image data of dtype object cannot be converted to float
  </code></pre>
  <p>The code is the following:</p>
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  import os
  import cv2
  from tqdm import tqdm
  from PIL import Image
  from scipy import ndimage, misc
  
  DATADIR = r&quot;C:\Users\robda\Desktop\Università\Corsi Luiss\ML &amp; AI\dog vs cat\Petimages&quot;
  CATEGORIES = [&quot;Dog&quot;, &quot;Cat&quot;]
  
  for category in CATEGORIES:  # do dogs and cats
      path = os.path.join(DATADIR,category)  # create path to dogs and cats
      for img in os.listdir(path):  # iterate over each image per dogs and cats
          img_array = cv2.imread(os.path.join(path,img) ,cv2.IMREAD_GRAYSCALE)  # convert to array
          plt.imshow(img_array, cmap='gray')  # graph it
          plt.show()  # display!
          break  
      break  
  </code></pre>