title: TypeError: cannot perform reduce with flexible type in flask
body: <p><a href="https://i.stack.imgur.com/f48Op.png" rel="nofollow noreferrer">i need some one to help me on this flask project </a></p>
  <p>i 'm doing a classification program that classifies Alzheimer's and i need to solve this problem in line 82 and line 87</p>
  <pre><code>@app.route('/predict', methods=['GET', 'POST'])
  def predict():
  if request.method == 'POST':
      # Get the image from post request
      img = base64_to_pil(request.json)
  
      # Save the image to ./uploads
      img.save(&quot;image.png&quot;)
      image_width, image_height = 224, 224
      img = image.load_img(&quot;image.png&quot;, target_size=(image_width, image_height))
      # Make prediction
      classes = {'MildDemented': 0,'ModerateDemented': 1,'NonDemented': 2,'VeryMildDemented': 3}
      new_dict = {value:key for (key,value) in classes.items()}
      preds = new_dict[np.argmax(model_predict(img))]
  
      # Process your result for human
      pred_proba = &quot;{:.3f}&quot;.format(np.amax(preds))    # Max probability
      result = str(preds)              # Convert to string
      # result = result.replace('_', ' ').capitalize()
      
      # Serialize the result, you can add additional fields
      return jsonify(result=result, probability=pred_proba)
  
  return None
  </code></pre>
  <p>Error</p>
  <pre><code>Traceback (most recent call last):
    File &quot;C:\Users\gouda\myenv\lib\site-packages\flask\app.py&quot;, line 2073, in wsgi_app
      response = self.full_dispatch_request()
    File &quot;C:\Users\gouda\myenv\lib\site-packages\flask\app.py&quot;, line 1518, in full_dispatch_request
      rv = self.handle_user_exception(e)
    File &quot;C:\Users\gouda\myenv\lib\site-packages\flask\app.py&quot;, line 1516, in full_dispatch_request
      rv = self.dispatch_request()
    File &quot;C:\Users\gouda\myenv\lib\site-packages\flask\app.py&quot;, line 1502, in dispatch_request
      return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
    File &quot;c:/Users/gouda/Desktop/graduation project/keras-flask-deploy-webapp-master/app.py&quot;, line 82, in predict
      pred_proba = float(&quot;{:.3f}&quot;.format(np.max(preds)))    # Max probability
    File &quot;&lt;__array_function__ internals&gt;&quot;, line 5, in amax
    File &quot;C:\Users\gouda\myenv\lib\site-packages\numpy\core\fromnumeric.py&quot;, line 2705, in amax
      return _wrapreduction(a, np.maximum, 'max', axis, None, out,
    File &quot;C:\Users\gouda\myenv\lib\site-packages\numpy\core\fromnumeric.py&quot;, line 87, in _wrapreduction
      return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
  TypeError: cannot perform reduce with flexible type
  127.0.0.1 - - [2021-12-18 02:02:39] &quot;POST /predict HTTP/1.1&quot; 500 426 3.283108
  </code></pre>