exps = np.array(exps) ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was (100, 5) + inhomogeneous part.
时间: 2023-07-24 10:19:09 浏览: 458
exslt.github.io:EXSLT 网站
这个错误通常是因为你尝试将一个不规则的列表转换为 NumPy 数组。这通常发生在列表中有不同长度的子列表。例如:
```python
my_list = [[1, 2, 3], [4, 5], [6, 7, 8, 9]]
my_array = np.array(my_list)
```
会产生类似这样的错误:
```
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.
```
在这种情况下,你可以考虑使用 Pandas 库的 DataFrame 类型,它可以处理不同长度的子列表。例如:
```python
import pandas as pd
my_list = [[1, 2, 3], [4, 5], [6, 7, 8, 9]]
my_dataframe = pd.DataFrame(my_list)
my_array = my_dataframe.values
```
如果你需要进一步帮助,请提供更多的上下文和代码。
阅读全文