import numpy as np
a=np.random.randn(1, 2)
b=np.zeros((1,2))
print("Data type of A: ",type(a))
print("Data type of A: ",type(b))
Output:
Data type of A: <class 'numpy.ndarray'>
Data type of A: <class 'numpy.ndarray'>
In np.zeros(), to declare an array we give the input in 2 brackets whereas in np.random.radn(), we give it in 1 bracket?
Is there any specific reason for the syntax,as both of them are of same data type but follow a different syntax?
In an effort to ease the transition for Matlab users to NumPy, some convenience functions like randn
were built which use the same call signature as their Matlab equivalents.
The more NumPy-centric (as opposed to Matlab-centric) NumPy functions (such as np.zeros
) expect the size
(or shape
) to be a tuple. This allows other parameters like dtype
and order
to be passed to the function as well.
The Matlab-centric functions assume all the arguments are part of the size.
np.random.randn
is one of NumPy's Matlab-centric convenience functions, modeled after Matlab's randn. The more NumPy-centric alternative to np.random.randn
is np.random.standard_normal
.
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