array() takes from 1 to 2 positional arguments but 9 were given
时间: 2023-11-07 20:52:01 浏览: 174
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 4 were givenarray() takes from 1 to 2 positional arguments but 4 were given
This error message is indicating that the function `array()` was called with four arguments, but it can only accept one or two positional arguments. A positional argument is an argument that is not a keyword argument, meaning it is not passed with a named parameter.
For example, if you were to call `array(1, 2, 3, 4)` this would result in the error message because `array()` only accepts one or two positional arguments.
To fix this error, you should check the number of arguments you are passing to the `array()` function and make sure it is within the allowed range of one or two positional arguments. If you need to pass more arguments, you may need to use a different function or modify the existing function to accept more arguments.
array() takes from 1 to 2 positional arguments but 4 were given
这个错误提示是因为您传递给array()函数的参数数量不匹配。array()函数的第一个参数是数组中的元素,第二个参数(可选)是布尔值,标志是否保留键。您可能误传递了额外的参数。
请检查您的代码,确保array()函数的参数数量与实际需要的参数数量匹配。如果您有进一步的问题,请提供更多细节,我可以帮助您解决它们。
阅读全文