ValueError: Expected 1D or 2D array, got 0D array instead
时间: 2024-05-15 19:15:38 浏览: 461
python3.7解决最小二乘遇到ValueError:Expected 2D array, got 1D array instead: array=[5.].关于reshape和predict
This error occurs when you try to pass a scalar value (0D array) to a function that expects a 1D or 2D array as input.
For example, if you have a function that takes an array of numbers and you pass a single number instead of an array, you will get this error.
To fix this error, make sure that you pass an array with the correct dimensions to the function. If you want to pass a single value, you can create a 1D array with that value using the numpy library:
```python
import numpy as np
# create a 1D array with a single value
a = np.array([5])
# pass the array to the function
result = my_function(a)
```
Alternatively, you can modify the function to handle scalar values properly.
阅读全文