Object of type ndarray is not JSON serializable

在尝试将numpy数组转换为JSON时遇到错误'Object of type ndarray is not JSON serializable'。解决方案是将numpy array转换为普通list,以便能够进行JSON序列化。
摘要由CSDN通过智能技术生成

今天在用Python实现前端跟后端的数据交换,结果出现了这个bug。原因就是json不认numpy的array,所以可以把psnr_list直接作为list传入,不用转为array.

  # run test and set results
            file_name = 'conditional_gan.py'
            if(os.path.getsize(save_path)==0):
                t = threading.Thread(target=run_python, args=(test_path,file_name))
                t.start()

            # read txt file, get corresponding psnr value for each generated .hdr
            psnr_list = []
            with open(os.path.join(save_path, 'psnr.txt'),'r') as f:
                while True:
                    lines = f.readline()  # 整行读取数据
                    if not lines:
                        break
                    if (lines[0] == 'b' or lines[0] == '\n'):
                        continue
                    _, E_tmp = [i for i in lines.split(':')]  # 将整行数据分割处理,如果分割符是空格,括号里就不用传入参数,如果是逗号
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值