python
data_error
ai_generated
true
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (3,) + inhomogeneous part.
ID: python/numpy-visible-deprecation-ragged
80%Fix Rate
88%Confidence
0Evidence
2024-02-14First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
np.array() called on a list of lists with differing lengths. Since NumPy 1.24 this raises instead of creating an object array.
generic中文
对长度不一致的列表的列表调用 np.array()。自 NumPy 1.24 起会报错而不是创建 object 数组。
Workarounds
-
95% success
np.array(data, dtype=object) to explicitly request an object array
-
85% success
Pad sequences first: from itertools import zip_longest; np.array(list(zip_longest(*data, fillvalue=0))).T
Dead Ends
Common approaches that don't work:
-
90% fail
Still cannot broadcast ragged data
-
85% fail
np.stack requires identical shapes too