当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python numpy.diagflat()用法及代码示例


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。