filmov
tv
Python Program Python | Matrix creation of n*n

Показать описание
# Python3 code to demonstrate
# matrix creation of n * n
# using list comprehension
# initializing N
N = 4
# printing dimension
print("The dimension : " + str(N))
# using list comprehension
# matrix creation of n * n
res = [list(range(1 + N * i, 1 + N * (i + 1)))
for i in range(N)]
# print result
print("The created matrix of N * N: " + str(res))
Output :
The dimension : 4
The created matrix of N*N: [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]
# matrix creation of n * n
# using list comprehension
# initializing N
N = 4
# printing dimension
print("The dimension : " + str(N))
# using list comprehension
# matrix creation of n * n
res = [list(range(1 + N * i, 1 + N * (i + 1)))
for i in range(N)]
# print result
print("The created matrix of N * N: " + str(res))
Output :
The dimension : 4
The created matrix of N*N: [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]