Why does json.dumps(list(np.arange(5))) fail while json.dumps(np.arange(5).tolist()) works

前端 未结 3 1578
鱼传尺愫
鱼传尺愫 2020-12-09 03:15

I noticed this problem when a computer running Ubuntu was updated recently and the default version of Python changed to 2.7.

import json
import numpy as np

         


        
3条回答
  •  一生所求
    2020-12-09 03:39

    The problem is that with the first you don't get an int. You get a numpy.int64. That cannot be serialized.

提交回复
热议问题