title: How to convert image which type is bytes to numpy.ndarray?
body: <p>I'm trying to optimize my code. </p>
  
  <p>First, I get an image, which type is bytes</p>
  
  <p>Then I have to write that image to file system.</p>
  
  <pre><code>with open('test2.jpg', 'wb') as f:
      f.write(content)
  </code></pre>
  
  <p>Finally I read this image with </p>
  
  <pre><code>from scipy import misc
  misc.imread('test2.jpg')
  </code></pre>
  
  <p>which convert image to np.array.</p>
  
  <p>I want to skip part where I write image to file system, and get np.array.</p>
  
  <p><strong>P.S.</strong>: I tried to use np.frombuffer(). It doesn't work for me, cause two np.arrays are not the same.
  <a href="https://stackoverflow.com/questions/47977474/convert-str-to-numpy-ndarray">Convert str to numpy.ndarray</a></p>
  
  <p>For test you can try yourself:</p>
  
  <pre><code>file = open('test1.jpg', 'rb')
  content = file.read()
  </code></pre>