Get Website Learn Coding Tech Story

Python Programming Examples

#!/usr/bin/evn python

# 2D array
x = [[1,2,3],
        [4,5,6],
        [7,8,9]]

y = [[9,8,7],
        [6,5,4],
        [3,2,1]]

mSum = [[0,0,0],
                [0,0,0],
                [0,0,0]]

# Iterate through rows
for i in range(len(x)):
    # Iterate through columns
    for j in range(len(x[0])):
        mSum[i][j] = x[i][j] + y[i][j]

for mxs in mSum:
    print(mxs)


# ***** Output *****
[10, 10, 10]
[10, 10, 10]
[10, 10, 10]

Learn more about Multi-dimensional Arrays