numpy.diagflat(a,k = 0):創建一個二維數組,其數組輸入作為新輸出數組的對角線。
參數:
a : array_like input data with diagonal elements strong>k : [int, optional, 0 by default] Diagonal we require; k>0 means diagonal above main diagonal or vice versa.
返回值:
array with the array_like input as a diagonal to the new output array.
# Python Program illustrating
# numpy.diagflat method
import numpy as geek
print("diagflat use on main diagonal : \n", geek.diagflat([1, 7]), "\n")
print("diagflat use on main diagonal : \n", geek.diagflat([1, 7, 6]), "\n")
# Diagnol above main diagnol
print("diagflat above main diagonal : \n", geek.diagflat([1, 7, 6], 1), "\n")
輸出:
diagflat use on main diagonal : [[1 0] [0 7]] diagflat use on main diagonal : [[1 0 0] [0 7 0] [0 0 6]] diagflat above main diagonal : [[0 1 0 0] [0 0 7 0] [0 0 0 6] [0 0 0 0]]
相關用法
注:本文由純淨天空篩選整理自 numpy.diagflat() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。