2D Array in Python
2D Array in Python
2D Array
Two dimensional array is an array within an array. It is an array of arrays. In this type of
array the position of an data element is referred by two indices instead of one. So it represents a
table with rows a columns of data.
Day 1 - 11 12 5 2
Day 2 - 15 6 10
Day 3 - 10 8 12 5
Day 4 - 12 15 8 6
The data elements in two dimensional arrays can be accessed using two indices. One
index referring to the main or parent array and another index referring to the position of the data
element in the inner array.
print(T[3])
print(T[1][0])
We can insert new data elements at specific position by using the insert() method and
specifying the index.
T.insert(2, [0,5,11,13,6])
for r in T:
for c in r:
print()
We can update the entire inner array or some specific data elements of the inner array by
reassigning the values using the array index.
Sample Code: In the code example, The entire array in element two is updated as well as the
specific inner array.
T[0][3] = 7
for r in T:
for c in r:
print()
The entire inner array or some specific data elements of the inner array can be deleted by
reassigning the values using the del() method with index.
del T[3]
for r in T:
for c in r:
print()