今天爱分享给大家带来KeyError: ‘data‘【解决方法】,希望能够帮助到大家。
KeyError: ‘data’
data = dicts['data']
if is_random_label is False:
label = np.array(dicts['labels'])
else:
labels = np.random.randint(low=0, high=10, size=10000)
label = np.array(labels)
return data, label
原因分析:
b:bytes python3.x里默认的str是unicode, bytes是py2.x的str, b''前缀代表的就是bytes python2.x里, b前缀没什么具体意义,只是为了兼容python3.x的这种写法
所以这主要是因为python2与python3的问题,直接在’data’和’lable’前面加上b就好了
加完代码如下:
data = dicts[b'data']
if is_random_label is False:
label = np.array(dicts[b'labels'])
else:
labels = np.random.randint(low=0, high=10, size=10000)
label = np.array(labels)
return data, label
原文链接:https://itblood.website/4371.html,转载请注明出处。

![双胞胎姐妹怀孕观察日记 内嵌汉化版 [PC+安卓] [800M [RPG/汉化]](/wp-content/uploads/replace/2025/07/19/24601103f21cfb36431234b512f32d36.webp)