In Python, lists, arrays, matrices convert each other's methods

Source: Internet
Author: User
This time to bring you a list in Python, arrays, matrices to convert each other's methods, in Python list, array, matrix to each other to the attention of the conversion, the following is the actual case, together to see.

Through the code familiarity process:

#-*-Coding:utf-8-*-from numpy import *a1 =[[1,2,3],[4,5,6]] #列表print (' A1: ', A1) # (' A1: ', [[1, 2, 3], [4, 5, 6]]) A2 = a Rray (A1) #列表-----> Array Print (' A2: ', A2) # (' A2: ', Array ([[[1, 2, 3],[4, 5, 6]])) A3 = Mat (A1) #列表----> Matrix print (' A3: ', A3) # (' A3: ', Matrix ([[1, 2, 3],[4, 5, 6]])) A4 = a3.tolist () #矩阵---> list print (' A4: ', A4) # (' A4: ', [[1, 2, 3], [4, 5, 6]) print (a1 = = a4) #Truea5 = a2.tolist () #数组---> List print (' A5: ', A5) # (' A5: ', [[1, 2, 3], [4, 5, 6]) Print (A5 = A1) #T  RUEA6 = Mat (a2) #数组---> Matrix print (' A6: ', A6) # (' A6: ', Matrix ([[[1, 2, 3],[4, 5, 6]]) print (A6 = A3) #[[true True true][ True true True]]a7 = Array (a3) #矩阵---> Array print (' A7: ', A7) # (' A7: ', array ([[[1, 2, 3],[4, 5, 6]]) print (a7 = a2) #[[Tr UE true true][true True true]]################################################################## #a1 =[1,2,3,4,5,6] # List print (' A1: ', A1) # (' A1: ', [1, 2, 3, 4, 5, 6]) a2 = array (a1) #列表-----> Array Print (' A2: ', A2) # (' A2: ', Array ([1, 2, 3, 4 , 5, 6])) A3 = Mat (A1) #列表----> Matrix print (' A3: ', A3) # (' A3: ', Matrix ([[[1, 2, 3, 4, 5, 6])) A4 = a3.tolist () #矩阵---> list print (' A4: ', A4) # (' A4: ',  [[1, 2, 3, 4, 5, 6]] #注意!! There are different print (A1 = = a4) #Falsea8 = a3.tolist () [0] #矩阵---> List print (' A8: ', A8) # (' A8: ', [1, 2, 3, 4, 5, 6]) #注意!!  There are different print (A1 = = a8) #Truea5 = a2.tolist () #数组---> List print (' A5: ', A5) # (' A5: ', [1, 2, 3, 4, 5, 6]) Print (A5 = A1) #Truea6 = Mat (A2) #数组---> Matrix print (' A6: ', A6) # (' A6: ', Matrix ([[[1, 2, 3, 4, 5, 6])) print (A6 = A3) #[[true True True Tr UE true]]a7 = Array (a3) #矩阵---> Array print (' A7: ', A7) # (' A7: ', Array ([[1, 2, 3, 4, 5, 6])) Print (a7 = a2) #[[true True T Rue true True]]

Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!

Recommended reading:

How to assign a uniform value to an array element in a NumPy

How to use the multiplication of numpy arrays and matrices

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.