array() takes from 1 to 2 positional arguments but 9 were given
时间: 2023-11-07 13:52:01 浏览: 39
array() 函数接受的位置参数范围是 1 到 2,但是给出了 9 个参数,这导致了 TypeError。要解决这个问题,你需要检查你的参数是否正确传递给了 array() 函数。
修改后的代码如下所示:
```python
import numpy as np
X = np.array([[0, 0], [0, 0], [1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5], [6, 6, 6], [7, 7, 7]])
```
这样,你将得到一个包含 9 个元素的二维数组。
相关问题
array() takes from 1 to 2 positional arguments but 48 were given
这个错误提示表明在调用`np.array()`函数时,传递的参数数量不正确。`np.array()`函数只接受1到2个位置参数,第一个位置参数是数组或嵌套序列,第二个位置参数是可选的数据类型。如果传递的参数数量超过了2个,就会出现这个错误。
<<修改案例>>
如果想要创建一个3行2列的数组,应该这样写:
```python
X = np.array([[0, 0], [0, 0], [1, 1]])
```
array() takes from 1 to 2 positional arguments but 4 were given
This error message is indicating that the `array()` function was called with too many arguments. The `array()` function can take between 1 and 2 positional arguments depending on how it is used, but in this case, it was called with 4 arguments.
To resolve this error, you should check the code that is calling the `array()` function and make sure that it is passing the correct number of arguments. If you are unsure how many arguments the `array()` function should be taking, you can consult the documentation or look up examples of how the function is used in other code.