使用 numpy 的方法调用的位置参数太多
Too many positional arguments for method call with numpy
我收到第 x_train = np.array(x_train).reshape(-1, SIZE, SIZE, 1)
行的错误 Too many positional arguments for method call
。关于如何解决这个问题有什么想法吗?
python3==3.8.3
pylint==2.5.3
astroid==2.5.3
numpy==1.18.5
ndarray.reshape
方法只接受两个位置参数:
https://numpy.org/doc/stable/reference/generated/numpy.ndarray.reshape.html#numpy.ndarray.reshape
使用 numpy
方法,允许任意数量的位置。是需要元组的函数形式
In [20]: np.arange(24).reshape(2,3,4)
Out[20]:
array([[[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]],
[[12, 13, 14, 15],
[16, 17, 18, 19],
[20, 21, 22, 23]]])
In [21]: np.reshape(np.arange(24),(2,3,4))
Out[21]:
array([[[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]],
[[12, 13, 14, 15],
[16, 17, 18, 19],
[20, 21, 22, 23]]])
或者更接近你的表达
In [25]: np.array(np.ones((3,4),int)).reshape(-1,2,2,1).shape
Out[25]: (3, 2, 2, 1)
这让我想知道您的 x_train
对象的性质。带有回溯的完整错误消息也可能有所帮助。
这真的是 Python/numpy 错误,还是 pylint 或 astroid 警告?
我收到第 x_train = np.array(x_train).reshape(-1, SIZE, SIZE, 1)
行的错误 Too many positional arguments for method call
。关于如何解决这个问题有什么想法吗?
python3==3.8.3
pylint==2.5.3
astroid==2.5.3
numpy==1.18.5
ndarray.reshape
方法只接受两个位置参数:
https://numpy.org/doc/stable/reference/generated/numpy.ndarray.reshape.html#numpy.ndarray.reshape
使用 numpy
方法,允许任意数量的位置。是需要元组的函数形式
In [20]: np.arange(24).reshape(2,3,4)
Out[20]:
array([[[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]],
[[12, 13, 14, 15],
[16, 17, 18, 19],
[20, 21, 22, 23]]])
In [21]: np.reshape(np.arange(24),(2,3,4))
Out[21]:
array([[[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]],
[[12, 13, 14, 15],
[16, 17, 18, 19],
[20, 21, 22, 23]]])
或者更接近你的表达
In [25]: np.array(np.ones((3,4),int)).reshape(-1,2,2,1).shape
Out[25]: (3, 2, 2, 1)
这让我想知道您的 x_train
对象的性质。带有回溯的完整错误消息也可能有所帮助。
这真的是 Python/numpy 错误,还是 pylint 或 astroid 警告?