KeyError:'numpy

问题描述 投票:0回答:1

我想从那个numpy数组的第二列中获取最大数字(许多行和2列),所以我写了此代码:

# …code that collects data and writes it to the raw_data list…
max_ccounts = raw_data[1][1].max(axis=0)[1]
print(max_ccounts)

但我不断收到以下错误:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/kimfook-lee/Desktop/automated_TPI.py", line 75, in <module>
    max_ccounts = raw_data[1][1].max(axis=0)[1]
    KeyError: '__builtins__'

我知道

raw_data[1][1]
指向一个numpy阵列,因为我打印了它。我不确定是否正确访问了列表元素,因此我尝试在终端中自己使用完全相同的numpy阵列:

>>> raw_data1 = np.array([[7200, 876],[8000,840271]]) >>> raw_data = [[0,raw_data1,10,10]] >>> max_ccounts = raw_data[0][1].max(axis=0)[1] >>> print(max_ccounts) 840271

当我搜索KeyError时,我只会找到与词典相关的内容,并且找不到与

__builtins__
或numpy有关的任何信息。
i添加了一些温度变量并打印它们以找到错误。

# …code that collects data and writes it to the raw_data list… tmp1 = raw_data[1] print('tmp1:', tmp1) tmp2 = tmp1[1] print('tmp2', tmp2) tmp3=tmp2.max(axis=0) print('tmp3', tmp3) tmp4 = tmp3[1] print('tmp4', tmp4)

现在有相同的错误和不同的追溯。

KeyError: '__builtins__' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/local/lib/python3.9/runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None, File "/usr/local/lib/python3.9/runpy.py", line 87, in _run_code exec(code, run_globals) File "/home/kimfook-lee/Desktop/automated_TPI.py", line 75, in <module> print('tmp1:', tmp1) RuntimeError: Unable to configure default ndarray.__repr__

是什么导致了此错误,如何解决?

    

cain弄清楚这个问题,但对我来说
import numpy as np

raw_data1 = np.array([[7200, 876],[8000,840271]])
raw_data = [[0,raw_data1,10,10]]
max_ccounts = raw_data[0][1].max(axis=0)[1]

print(max_ccounts)

输出

python numpy numpy-ndarray keyerror
1个回答
-1
投票

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.