builtins.ValueError: Expected 2D array, got 1D array instead:
时间: 2024-04-13 22:29:52 浏览: 156
Python库 | dolmen.builtins-0.3.tar.gz
To fix the `ValueError` you encountered, you need to reshape your 1D array into a 2D array. You can use the `reshape` method from NumPy to accomplish this. Here's an example of how to do it:
```python
import numpy as np
# Assuming your 1D array is called 'arr'
arr_2d = np.reshape(arr, (-1, 1))
# Now 'arr_2d' is a 2D array with a single column
```
In this example, `arr` is your 1D array and `arr_2d` is the reshaped 2D array. The `-1` in the `reshape` method's argument means that the size of that dimension will be inferred based on the size of the original array. The `1` specifies that the reshaped array should have a single column.
Make sure to replace `'arr'` with the actual name of your 1D array in your code.
阅读全文