2

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?

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

3 Comments

How would this change if we are using arrays instead? Also, for some reason, it isn't allowing me to upvote because I need 15 reputation which I don't know how to get. Sorry
Can you show the actual code? In lua, you have lua-table.
@Sibi Look for easy to answer Python questions, there's plenty of them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.