Table of Contents

Cvičení 5: 2D pole

Dvojrozměrné pole

x = [[0, 1], ['a', True], [1, 1.0, 2, 4]]
>>> len(x)
3
>>> len(x[0])
2
>>> x[1][1]
True
>>> type(x)
<class 'list'>
>>> type(x[0])
<class 'list'>

x = []
for i in range(2):
   x.append([0] * 3)
>>> print(x)
[[0, 0, 0], [0, 0, 0]]

Výpis matice

Stopa matice

Násobení vektoru a matice

m=[[0,0,1],[0,1,0],[1,0,0]]
v=[2, 4, 6]

Načtení 2D pole ze souboru

1 2 3
4 0 5
7 -1 2

pole=[]
f=open('matice.txt','rt')
for line in f:
    pole.append(list(map(int, line.split())))
f.close()
print(pole)

[[1,2,3],[4,0,5],[7,-1,2]]

Témata k procvičení

Implementujte následující úlohy: