0
import numpy as np    
a = np.arange(6).reshape(2,3)
np.meshgrid(*[np.arange(x) for x in a.shape])

What is the role of the asterisk before the parameter?

code

why does it works? what dose it mean adding an asterisk before list comprehension as a parameter?

DamonD
  • 21
  • 4

1 Answers1

0

In python, an * unrolls a list.

That way you can use a list as a set of arguments.

some_args = ['first', False, 3]

do_something(*some_args)

In your case, the following is unrolling a list comprehension.

*[np.arange(x) for x in a.shape]
Soviut
  • 88,194
  • 49
  • 192
  • 260