npz压缩数据读取错误:

272 阅读1分钟

场景

读取npz的字典,出现字典是<class 'numpy.ndarray'>格式,难以读取 在这里插入图片描述

错误

IndexError: only integers, slices (:), ellipsis (...), numpy.newaxis (None) and integer or boolean arrays are valid indices

用字典的方式索引出现 AttributeError:'numpy.ndarray' object has no attribute 'index'

原因和解决办法

numpy中的ndarray没有索引,因此需要转为list格式。

解决方法如下:

import numpy as np
array = array.tolist()

在这里插入图片描述 # 参考 https://blog.csdn.net/sinat_26811377/article/details/103125896