Home python How the numpy.dot function works

# How the numpy.dot function works

Author

Date

Category

Help me with the `numpy.dot `function. As it is not very clear description in the documentation. This function works the same as described in this article?

There is the following code:

``````Nj = 100
Nin = 100
Xin = np.zeros ((Nin, 1))
Winj = np.zeros ((Nin, Nj))
WinjT = np.transpose (Winj)
Uj = np.dot (WinjT, Xin)
``````

In theory, you should get an array Uj with Nj rows and 1 column, but you get a two-dimensional array.
The part of the code following the initialization is forgiven, since it is not relevant to the question.

product of scalars:

``````In : np.dot (2, 3)
Out : 6
``````

product of 1D arrays (vectors):

``````In : a = np.array ([1, 2])
In : b = np.array ([10, 11])
In : np.dot (a, b)
Out : 32
``````

product of 2D arrays:

``````In : a = np.array ([[1,2], [3,4]] )
In : b = np.array ([[2,3], [4,5]])
In : a
Out :
array ([[1, 2],
[3, 4]])
In : b
Out :
array ([[2, 3],
[4, 5]])
In : np.dot (a, b)
Out :
array ([[10, 13],
[22, 29]])
``````

Explanation:

``````10: 1 * 2 + 2 * 4
13: 1 * 3 + 2 * 5
22: 3 * 2 + 4 * 4
29: 3 * 3 + 4 * 5
``````

``````In :% paste
Nj = 100
Nin = 100
Xin = np.zeros ((Nin, 1))
Winj = np.zeros ((Nin, Nj))
WinjT = np.transpose (Winj)
Uj = np.dot (WinjT, Xin)
## - End pasted text -
``````

The result is a 2D array, consisting of 100 rows and one column:

``````In : Uj.shape
Out : (100, 1)
``````

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.