MPLD3 with Python error

五迷三道 提交于 2019-11-29 16:18:11

There is an open issue raised against this error, the link is https://github.com/mpld3/mpld3/pull/435

One work-around is to edit the mpld3/_display.py file inside your mpld3 module, the edit will be on below default function

before:

def default(self, obj):
    if isinstance(obj, (numpy.int_, numpy.intc, numpy.intp, numpy.int8,
        numpy.int16, numpy.int32, numpy.int64, numpy.uint8,
        numpy.uint16,numpy.uint32, numpy.uint64)):
        return int(obj)
    elif isinstance(obj, (numpy.float_, numpy.float16, numpy.float32, 
        numpy.float64)):
        return float(obj)
    return json.JSONEncoder.default(self, obj)

after:

def default(self, obj):
    if isinstance(obj, (numpy.int_, numpy.intc, numpy.intp, numpy.int8,
        numpy.int16, numpy.int32, numpy.int64, numpy.uint8,
        numpy.uint16,numpy.uint32, numpy.uint64)):
        return int(obj)
    elif isinstance(obj, (numpy.float_, numpy.float16, numpy.float32, 
        numpy.float64)):
        return float(obj)
    elif isinstance(obj, (numpy.ndarray,)): # add this line
        return obj.tolist() # add this line
    return json.JSONEncoder.default(self, obj)

basically you just added

elif isinstance(obj, (numpy.ndarray,)): # add this line
            return obj.tolist() # add this line
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!