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:
- int** pTwoDimArr = new int[10][20];
- pTwoDimArr[0][0] = 5;
-
This seems intuitive. However, compilation may fail:
- cannot convert from 'int (*)[20]'
- to 'int ** '
If so: Yes, but the memory of this Python two-dimensional array is allocated on the stack, so,
- void main(){
- int pTwoDimArr[1000][1000];
- }
If so:
- int (*pTwoDimArr)[1000] = new int[1000][1000];
- 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 ).