tf.matrix_band_part(input,num_lower,num_upper,name=None)

2022-09-25 09:08:17
tf.matrix_band_part(input,num_lower,num_upper,name=None)

功能:复制一个矩阵,并将规定带之外的元素置为0。
假设元素坐标为(m,n),则in_band(m, n) = (num_lower < 0 || (m-n) <= num_lower)) &&
(num_upper < 0 || (n-m) <= num_upper)。
band(m,n)=in_band(m,n)*input(m,n)。
特殊情况:

          tf.matrix_band_part(input, 0, -1) ==> 上三角阵.
          tf.matrix_band_part(input, -1, 0) ==> 下三角阵.
          tf.matrix_band_part(input, 0, 0) ==> 对角阵.

输入:num_lower:如果为负,则结果右上空三角阵;
num_lower:如果为负,则结果左下为空三角阵。
例:

a=tf.constant([[0,1,2,3],[-1,0,1,2],[-2,-1,0,1],[-3,-2,-1,0]])
z=tf.matrix_band_part(a,1,-1)
z==>[[0 1 2 3]
     [-1 0 1 2]
     [0 -1 0 1]
     [0 0 -1 0]]

作者:华夏意匠
链接:https://www.jianshu.com/p/336772764fef
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

  • 作者:sigma_Tian
  • 原文链接:https://blog.csdn.net/tcx1992/article/details/80307630
    更新时间:2022-09-25 09:08:17