numpy.tri(R,C = None,k = 0,dtype ='float'):創建一個數組,數組在給定的對角線(約k)處和對角線以下(小於k),在其他位置為0。
參數:
R : Number of rows C : [optional] Number of columns; By default R = C k : [int, optional, 0 by default] Diagonal we require; k>0 means diagonal above main diagonal or vice versa. dtype : [optional, float(byDefault)] Data type of returned array.
# Python Program illustrating
# numpy.tri method
import numpy as geek
print("tri with k = 1 : \n",geek.tri(2, 3, 1, dtype = float), "\n")
print("tri with main diagonal : \n",geek.tri(3, 5, 0), "\n")
print("tri with k = -1 : \n",geek.tri(3, 5, -1), "\n")
輸出:
tri with k = 1 : [[ 1. 1. 0.] [ 1. 1. 1.]] tri with main diagonal : [[ 1. 0. 0. 0. 0.] [ 1. 1. 0. 0. 0.] [ 1. 1. 1. 0. 0.]] tri with k = -1 : [[ 0. 0. 0. 0. 0.] [ 1. 0. 0. 0. 0.] [ 1. 1. 0. 0. 0.]]
相關用法
注:本文由純淨天空篩選整理自 numpy.tri() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。