Steps for creating a Python two-dimensional array

Source: Internet
Author: User

It may be difficult to implement Python two-dimensional arrays in the eyes of many people. In fact, if you are familiar with the practical application skills of Python two-dimensional arrays, you will be very open to them, the following article describes the skills related to its practical application.

Originally, Python and other dynamic languages are much easier to process multi-dimensional arrays than C ++. It seems like the opposite. Here I want to clarify that the processing in Python is definitely not as simple as the array. For example, to dynamically create a Python two-dimensional array:

 
 
  1. int**   pTwoDimArr   =   new   int[10][20];     
  2. pTwoDimArr[0][0]   =   5;     
  3.       

This seems intuitive. However, compilation may fail:

 
 
  1. cannot   convert   from   'int   (*)[20]'   
  2. to   'int   **   '     

    
 

If so: Yes, but the memory of this Python two-dimensional array is allocated on the stack, so,

 
 
  1. void   main(){     
  2. int   pTwoDimArr[1000][1000];     
  3.  }    

  
 

If so:

 
 
  1. int   (*pTwoDimArr)[1000]   =   new   int[1000][1000];     
  2. pTwoDimArr[0][0]   =   5;     

Dynamic Allocation is acceptable. Remember to release the memory, and the Python two-dimensional array must be fixed with the first-dimension changeable ).


 

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.