What is the meaning of "*" in numpy?
This is not NumPy specific syntax; This is Python syntax. The so-called *
-operator is Python syntax that decompresses a sequence of argument lists (see Unpacking argument lists ).
The use in your example is to unpack the shape
tuple into separate arguments. This is necessary because numpy.random.randn
accepts an arbitrary number of integers as parameters, rather than a set of integers.
The code from the question is equivalent to doing:
>>> np.random.randn(2, 2)
People from other places sometimes call it "splat". (for completeness, **
does the same, but with named / keyword arguments).