我可以使用 `namedtuple` 为一维数组的元素命名吗?

Can I use `namedtuple` to give names to the elements of a 1D array?

res.x是我优化一个objective函数得到的数组,我想给每个元素起一个名字这样我就可以更多的使用它们以后方便。我最初的想法是使用 namedtuple,但显然 Python 只会将数组作为第一个参数并报告其余的缺失。有出路吗?有人可以帮助我吗?

from collections import namedtuple

Coef = namedtuple("Coefficients", ["alpha","beta","gamma"])
t = Coef(res.x)

回溯(最近调用最后):

文件“”,第 1 行,在

TypeError:__new__() 缺少 2 个必需的位置参数:'beta'、'gamma'

from collections import namedtuple

Coef = namedtuple("Coefficients", ["alpha","beta","gamma"])
t = Coef(*res.x)

通过在列表前面放置一个 *,python 会将数组拆分为 3 个不同的参数。