gpt4 book ai didi

python - Lua 函数返回值的元组

转载 作者:太空宇宙 更新时间:2023-11-04 08:48:41 24 4
gpt4 key购买 nike

我看过下面的python代码:

W_grads, _ = backward_gradient(X, S, grad_out, wRec)

在函数 backward_gradient 中,我有以下返回语句:

return (wx_grad, wRec_grad), grad_over_time

如何在lua中返回类似上述的元组,以便在torch中实现?

最佳答案

您可以为此使用表格。

return {wx_grad, wRec_grad}, grad_over_time

有关详细信息,请参阅 http://www.lua.org/manual/5.3/manual.html#2.1

Tables are the sole data-structuring mechanism in Lua; they can be used to represent ordinary arrays, sequences, symbol tables, sets, records, graphs, trees, etc. To represent records, Lua uses the field name as an index. The language supports this representation by providing a.name as syntactic sugar for a["name"]. There are several convenient ways to create tables in Lua (see §3.4.9).

关于python - Lua 函数返回值的元组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37541444/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com