0

I have a python function of many parameters

foo(x_1,...x_N)

Is there a pythonic way to transform it to a function that accepts a list of numpy.array?

3
  • Do you mean I could have used foo directly for numpy.array? Commented Dec 17, 2015 at 6:58
  • make your function accept only one argument and then put all your params into a np.array Commented Dec 17, 2015 at 6:59
  • Or you need foo(*X)? Commented Dec 17, 2015 at 6:59

2 Answers 2

1

Are you looking for:

x = [1, 2, 3, 4, 5]
foo(*x)  # calls foo(1, 2, 3, 4, 5)
Sign up to request clarification or add additional context in comments.

2 Comments

It works! Thanks. But what is the strange syntax? Does '*' mean dereference?
That syntax means pass each element of the iterable as a positional argument. There's also **dict for keyword args.
0

You can simply define the function as def foo(mylist) and then do whatever you want with it inside the function.

def foo(mylist):
    ''' mylist: an iterable '''
    for item in mylist: # example
        print(item) 

1 Comment

@zell Why would it not be?

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.