>>> shape=(2,2)
>>> np.random.randn(*shape)
array([[-1.64633649, -0.03132273],
[-0.92331459, 1.05325462]])
I can't find it in numpy's documentation. Any help is appreciated.
The [:, :] stands for everything from the beginning to the end just like for lists. The difference is that the first : stands for first and the second : for the second dimension. a = numpy. zeros((3, 3)) In [132]: a Out[132]: array([[ 0., 0., 0.], [ 0., 0., 0.], [ 0., 0., 0.]])
NumPy axes are the directions along the rows and columns. Just like coordinate systems, NumPy arrays also have axes. In a 2-dimensional NumPy array, the axes are the directions along the rows and columns.
np. mean always computes an arithmetic mean, and has some additional options for input and output (e.g. what datatypes to use, where to place the result). np. average can compute a weighted average if the weights parameter is supplied.
This is not NumPy-specific syntax; it is Python syntax. The so-called *
-operator is Python syntax that does sequence unpacking in argument lists (see Unpacking Argument Lists).
The use in your example is to unpack the shape
tuple into separate arguments. This is needed because numpy.random.randn
takes an arbitrary number of integers as parameters, not a tuple of integers.
The code from the question is equivalent to doing:
>>> np.random.randn(2, 2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With