numpy.diag

numpy.diag(v, k=0)

Leiab masiivist diagonaalväärtused


>>> x = np.arange(9).reshape((3,3))
>>> x
array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
>>> diag(x)
array([0, 4, 8])

>>> x = arange(25).reshape((5,5))
>>> x
array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14],
[15, 16, 17, 18, 19],
[20, 21, 22, 23, 24]])
>>>
>>> diag(x)
array([ 0, 6, 12, 18, 24])

>>> diag([0,10])
array([[ 0, 0],
[ 0, 10]])