3

I'm trying to do something like this in my code:

def fu():
    return np.array([1,2,3]), np.array([4,5,6])

def bar(x,y,z):
    print np.size(x)
    print np.size(y)
    print np.size(z)

bar(np.array([7,8]), fu())

but I'm getting an error message saying bar() takes exactly 3 arguments (2 given). How can I solve this problem?

2 Answers 2

5

Try this:

bar(np.array([7,8]), *fu())

(unpack the tuple returned by fu())

Sign up to request clarification or add additional context in comments.

Comments

0
import numpy as np

def fu():
   return np.array([1,2,3]), np.array([4,5,6])

def bar(x,y,z):
   print np.size(x)
   print np.size(y)
   print np.size(z)

bar(np.array([7,8]), *fu())

--output:--
2
3
3

3 Comments

How is this different than my answer?
@arshajii, I'm sorry, I didn't receive any telepathic warnings that you were answering the question at the same time I was. Did you send them?
You answered two minutes later, so I assumed I didn't need to send any telepathic warnings. In any case, I don't mean to be confrontational, just doing my part to keep the bowels of the inter-webs clutter-free.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.