📜  numpy diag() - Python 代码示例

📅  最后修改于: 2022-03-11 14:47:07.381000             🧑  作者: Mango

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

>>> np.diag(x)
array([0, 4, 8])
>>> np.diag(x, k=1)
array([1, 5])
>>> np.diag(x, k=-1)
array([3, 7])