numpy 错误:请求的数组在2维之后具有不均匀的形状

y1aodyip  于 5个月前  发布在  其他
关注(0)|答案(2)|浏览(70)

我有下面的代码和数据的一部分,在最终也提供了你可以看到.当我运行这个代码在vs代码在我的电脑我得到这个错误:

ultimate = np.array(ultimate)   
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was (81, 2) + inhomogeneous part.

字符串
然而,当我在另一台计算机上运行这段代码时,它没有显示任何错误,而且运行完全正确。有人能告诉我我的代码有什么问题吗?

for q in nonoutliersPos:
                ultimate.append(cluster0Data[q])
          print('ultimate:',ultimate)      
          ultimate = np.array(ultimate) 


ultimate:
[(array([3.72660978e+08, 4.16826783e+00, 6.76000000e-04, 0.00000000e+00,
       0.00000000e+00]), 199), (array([3.72660954e+08, 4.16826783e+00, 6.76000000e-04, 0.00000000e+00,
       0.00000000e+00]), 201), (array([3.72660978e+08, 4.16826783e+00, 6.76000000e-04, 0.00000000e+00,
       0.00000000e+00]), 202), (array([3.72660954e+08, 4.16826783e+00, 6.76000000e-04, 0.00000000e+00,
       0.00000000e+00]), 203), (array([ 2.63184231e+08,  4.16799028e+00, -7.13000000e-05, -4.55000000e-13,
        0.00000000e+00]), 211), (array([ 2.63184237e+08,  4.16799028e+00, -7.13000000e-05, -4.55000000e-13,
        0.00000000e+00]), 212)]


我在命令行中写了pip list。下面是答案:

Package         Version
--------------- ------------
contourpy       1.2.0
cycler          0.12.1
et-xmlfile      1.1.0
fonttools       4.44.3
joblib          1.3.2
kiwisolver      1.4.5
matplotlib      3.8.2
networkx        3.2.1
numpy           1.24.3
openpyxl        3.1.2
packaging       23.2
pandas          2.0.3
Pillow          10.1.0
pip             22.3.1
plotly          5.18.0
pyparsing       3.1.1
python-dateutil 2.8.2
pytz            2023.3.post1
ruptures        1.1.8
scikit-fuzzy    0.4.2
scikit-learn    1.3.2
scipy           1.11.4
setuptools      65.5.0
six             1.16.0
tenacity        8.2.3
threadpoolctl   3.2.0
tzdata          2023.3

jmo0nnb3

jmo0nnb31#

降低你的numpy
例如pip install numpy==1.23.0

oyxsuwqo

oyxsuwqo2#

你的代码是正确的:)这是一个版本问题。你应该降级到旧版本的numpy。
这是numpy所有版本的页面。您必须安装日期为 * 2022年6月23日 * 的版本,因此版本1.23.0 . Here is版本1.23.0页面。
首先卸载你的numpy(你可能不需要,但最好还是卸载)

pip uninstall numpy

字符串
然后安装它:

pip install numpy==1.23.0


P.S:如果这不起作用,那么安装日期为 * 2022年5月20日 * 的1.22.4,使用相同的方法

相关问题