ttina
ttina

Reputation: 97

error: The requested array has an inhomogeneous shape after 2 dimensions

I have the following code and the part of data in ultimate is also provided as you can see. When I run this code in vs code in my computer I get this error:

 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.

However, when. I run this code on another computer. It doesn't show any error and it runs totally correct. Can anyone suggest me what's wrong with my code?

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)]

I wrote pip list in command line. Here is the answer:

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

Upvotes: 1

Views: 2407

Answers (2)

Tappetinoorange
Tappetinoorange

Reputation: 85

Your code is correct :) It's a version problem. You should downgrade to an older version of numpy.

This is the page for all versions of numpy. You must install the one dated June 23, 2022, therefore version 1.23.0. Here is the version 1.23.0 page.

Uninstall your numpy first (you may not need to, but better to uninstall anyway)

pip uninstall numpy

Then install it with:

pip install numpy==1.23.0

P.S: If that doesn't work, then install 1.22.4 dated May 20, 2022, using the same method

Upvotes: 0

Lin
Lin

Reputation: 239

Degrade your numpy

e.g. pip install numpy==1.23.0

Upvotes: 1

Related Questions