Object of type 'ndarray' is not JSON serializable Object of type 'ndarray' is not JSON serializable flask flask

Object of type 'ndarray' is not JSON serializable


Try to convert your ndarray with tolist() method:

prediction = model.predict(np.array(X).tolist()).tolist()return jsonify({'prediction': prediction})

Example with json package:

a = np.array([1,2,3,4,5]).tolist()json.dumps({"prediction": a})

That should output:

'{"prediction": [1, 2, 3, 4, 5]}'