Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between single and double bracket Numpy array?

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?

like image 507
MVSN Bharath Avatar asked Oct 08 '17 17:10

MVSN Bharath


1 Answers

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.

like image 184
unutbu Avatar answered Oct 18 '22 00:10

unutbu