The solution of array transpose in numpy and the computation method of vector inner product

  • 2021-01-19 22:18:50
  • OfStack

I'm a little sorry that my math skills are really not good. After the tension in high school, I loosened up after college. Math, which had been a bit of a drag in high school, dropped dramatically in college. Linear algebra is not understood directly, as is probability and statistics, and functions of complex variables. To this day, I still think it is a shame in life. Fortunately, however, I still have the opportunity, in order not to perfunctory and to learn 1.

What function does the transpose of the matrix have? I really don't know. After summarizing the operation of the transpose of the matrix today, I will go to the network to add 1 relevant knowledge.

Today's code operations are as follows:


In [15]: arr1 = np.arange(20)


In [16]: arr1
Out[16]:
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
    17, 18, 19])


In [17]: arr2 = arr1.reshape((4,5))


In [18]: arr2
Out[18]:
array([[ 0, 1, 2, 3, 4],
    [ 5, 6, 7, 8, 9],
    [10, 11, 12, 13, 14],
    [15, 16, 17, 18, 19]])


In [19]: arr3 = arr2.T


In [20]: arr3
Out[20]:
array([[ 0, 5, 10, 15],
    [ 1, 6, 11, 16],
    [ 2, 7, 12, 17],
    [ 3, 8, 13, 18],
    [ 4, 9, 14, 19]])


In [21]: np.dot(arr3,arr2)
Out[21]:
array([[350, 380, 410, 440, 470],
    [380, 414, 448, 482, 516],
    [410, 448, 486, 524, 562],
    [440, 482, 524, 566, 608],
    [470, 516, 562, 608, 654]])

The Reshape method is used to change the dimensions of an array, and the T property is to implement the transpose of a matrix. From the results of calculation, the transpose of a matrix is actually the transformation of the matrix against the axis. And the common place for matrix transposes is to compute the inner product of matrices. And about the meaning of this arithmetic operation, I have not been clear, this is also the content of today's make-up lesson!

On the front of the two remedial lessons, read a pile of data is really bad to understand. But memorizing formulas all the time is not what I want, and I need to keep trying to understand them in the future. However, we have found a geometric explanation for the inner product, and we don't know if it is correct. The projection of a vector in a higher dimensional space to a subspace in a lower dimensional space, but after thinking about it for a long time, I still do not understand. It seems that linear algebra still needs to be understood.


Related articles: