简体   繁体   中英

Torch lua function to return multiple values

I would like to replicate the following python function in lua/torch.

def add_and_multiply(a,b):
    c=a+b;
    d=a*b;
    return c,d

How can I return two values simultaneously in lua/torch as above? Also, suppose a and b were matrices(with appropriate dimensions), how would the code change for torch?

The same thing happens in lua too. You can even skip using two extra local variables:

function add_and_multiply(a,b)
    return a + b, a * b
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM