Introduction
We have so far seen examples of 1D arrays.
But arrays can also be 2 dimensional (or multi-dimensional).
A 2D array can be though of as a table of data, and each element will have 2 indices, to indicate which row and which column it is in the table.
Data sometimes has more structure to it than just "a list" It has rows and columns You use two subscripts to locate an item The first subscript called “row”, second called “column”
syntax a = [[0]*5 for i in range(4)] # 5 columns, 4 rows Twenty elements, numbered from [0][0] to [4][3] a = [[0]*COLS for i in range(ROWS)] Which has ROWS rows and COLS columns in each row (use of variables to make it easy to change the size of the array without having to edit every line of the program)
As stated earlier, python doesn’t have an array as a native data structure. Instead, it offers the data structure: ‘List’.
Lists allow us to do most things that an array does. In addition to this, we can create 2 dimensional lists with ease.
A 2 dimensional list is simply: ‘lists inside a list’
المادة المعروضة اعلاه هي مدخل الى المحاضرة المرفوعة بواسطة استاذ(ة) المادة . وقد تبدو لك غير متكاملة . حيث يضع استاذ المادة في بعض الاحيان فقط الجزء الاول من المحاضرة من اجل الاطلاع على ما ستقوم بتحميله لاحقا . في نظام التعليم الالكتروني نوفر هذه الخدمة لكي نبقيك على اطلاع حول محتوى الملف الذي ستقوم بتحميله .
|