Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python namedtuple接受3个参数?_Python_Python 3.x_Namedtuple - Fatal编程技术网

Python namedtuple接受3个参数?

Python namedtuple接受3个参数?,python,python-3.x,namedtuple,Python,Python 3.x,Namedtuple,正在尝试在Python3 Jupyter笔记本中运行此代码: t = namedtuple('a', 'b') a = [1,0,1] b = [1,1,1] Out, In = np.asanyarray(a), np.asanyarray(b) t(Out.shape[0], *In.shape) 返回错误: --------------------------------------------------------------------------- TypeError

正在尝试在Python3 Jupyter笔记本中运行此代码:

t = namedtuple('a', 'b')
a = [1,0,1]
b = [1,1,1]
Out, In = np.asanyarray(a), np.asanyarray(b)
t(Out.shape[0], *In.shape)
返回错误:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-151-7955ff03a60d> in <module>()
      3 b = [1,1,1]
      4 Out, In = np.asanyarray(a), np.asanyarray(b)
----> 5 t(Out.shape[0], *In.shape)

TypeError: __new__() takes 2 positional arguments but 3 were given
计算:

ps(Out=1, In=1, S=1)
更新2:


我想我现在理解了namedtuple'ps'、'Out In S'转换为namedtuple'name\u of tuple'、'tuple\u values\u由空间分隔'

命名元组构造函数的第一个参数是typename:命名元组的名称,而不是参数

因此,您应该将t构造为:

为了更加方便,还可以提供一个以空格分隔的参数字符串。因此,一个等价的是:

#t = namedtuple('t', 'a b')
#                    ^ space separated list of parameters

命名元组构造函数的第一个参数是typename:命名元组的名称,而不是参数

因此,您应该将t构造为:

为了更加方便,还可以提供一个以空格分隔的参数字符串。因此,一个等价的是:

#t = namedtuple('t', 'a b')
#                    ^ space separated list of parameters

命名元组的第一个参数是命名元组的名称,而不是参数。您使用的命名元组不正确。命名元组的第一个参数是命名元组的名称,而不是参数。您使用的命名元组不正确。
#t = namedtuple('t', 'a b')
#                    ^ space separated list of parameters