numpy.diag(a,k = 0):提取并构造对角行数组
参数:
a : array_like k : [int, optional, 0 by default] Diagonal we require; k>0 means diagonal above main diagonal or vice versa.
返回值:
ndarray
# Python Programming illustrating
# numpy.diag method
import numpy as geek
# matrix creation by array input
a = geek.matrix([[1, 21, 30],
[63 ,434, 3],
[54, 54, 56]])
print("Main Diagnol elements : \n", geek.diag(a), "\n")
print("Diagnol above main diagnol : \n", geek.diag(a, 1), "\n")
print("Diagnol below main diagnol : \n", geek.diag(a, -1))
输出:
Main Diagnol elements : [ 1 434 56] Diagnol above main diagnol : [21 3] Diagnol below main diagnol : [63 54]
相关用法
注:本文由纯净天空筛选整理自 numpy.diag() in Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。