Python matrix transpose Transpose

Source: Internet
Author: User

When you read a picture, you use a code like this:

Image_vector_len = Np.prod (image_size) #总元素大小, 3*55*47

img = image.open (path) arr_img = Np.asarray (img, dtype= ' float64 ') arr_img = Arr_img.transpose (2,0,1). Resha PE ((Image_vector_len,)) # 47 rows, 55 columns, each point has 3 element RGB. And put these elements in a row.

What is the consciousness of transpose? See the following example:

arr1 = Array ([[[[0, 1, 2, 3],

[4, 5, 6, 7]],

[[8, 9, 10, 11],
[12, 13, 14, 15]])
This is the original matrix. If you transpose it, execute arr2 = Arr1.transpose ((1,0,2))
Get: Array ([[[[[0], 1, 2, 3],
[8, 9, 10, 11]],

[[4, 5, 6, 7],
[12, 13, 14, 15]])

What is the process?

Arr1.shape should be (2, 2, 4) meaning 2-dimensional, 2*4 matrix

Arr1.transpose (*args) inside the parameters, so to understand, he is the order of exchange Arr1.shape, we come to the arr1.shape labeled the Horn Kazakhstan, (2[0], 2[1], 4[2]) [] is the index of shape, right,
Transpose ((1, 0, 2)) means to re-set shape in this order (2[1], 2[0], 4[2])

Although it seems that the shape before and after the transformation is 2,2,4, the problem is that transpose is the transpose
The shape is reset in the order (1,0,2), and all elements in the array are re-formed with the new matrix.

For example, 8 in the ARR1 index is (1, 0, 0) then according to the change rule, that is (0, 1, 0) look at the same position as your result arr2, and so on.

Python matrix transpose Transpose

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.