codecamp

TensorFlow矩阵数学函数:tf.matrix_band_part

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

参考指南:数学函数>矩阵数学函数

复制一个张量,将每个最内层矩阵中的所有中心区域外的所有内容设置为零.

该 band 部分计算如下:假设 input 有 k 维 [I, J, K, ..., M, N],则输出是具有相同形状的张量:

band[i, j, k, ..., m, n] = in_band(m, n) * input[i, j, k, ..., m, n]

指示器函数:

in_band(m, n) = (num_lower < 0 || (m-n) <= num_lower)) && (num_upper < 0 || (n-m) <= num_upper)

例如:

# if 'input' is [[ 0,  1,  2, 3]
                 [-1,  0,  1, 2]
                 [-2, -1,  0, 1]
                 [-3, -2, -1, 0]],

tf.matrix_band_part(input, 1, -1) ==> [[ 0,  1,  2, 3]
                                       [-1,  0,  1, 2]
                                       [ 0, -1,  0, 1]
                                       [ 0,  0, -1, 0]],

tf.matrix_band_part(input, 2, 1) ==> [[ 0,  1,  0, 0]
                                      [-1,  0,  1, 0]
                                      [-2, -1,  0, 1]
                                      [ 0, -2, -1, 0]]

有用的特殊情况:

tf.matrix_band_part(input, 0, -1) ==> Upper triangular part.
tf.matrix_band_part(input, -1, 0) ==> Lower triangular part.
tf.matrix_band_part(input, 0, 0) ==> Diagonal.

参数:

  • input:张量.秩为 k 的张量.
  • num_lower:int64 类型的张量;0-D 张量;要保持的对角线的数量;如果为负,则保留整个下三角.
  • num_upper:int64 类型的张量;0-D 张量;要保留的 superdiagonals 数;如果为负,则保持整个上三角.
  • name:操作的名称(可选).

返回值:

该函数将返回一个张量,该张量与 input 具有相同的类型;与 input 具有相同形状的秩为 k 的张量;提取的带状张量.

TensorFlow:tf.matmul函数
TensorFlow计算方阵行列式的函数
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

TensorFlow 函数介绍

TensorFlow 函数模块:tf

TensorFlow的image模块

TensorFlow使用之tf.io

TensorFlow使用之tf.keras

TensorFlow函数教程:tf.keras.applications

TensorFlow函数教程:tf.keras.backend

TensorFlow使用之tf.metrics

TensorFlow使用之tf.nn

TensorFlow使用之tf.python_io

TensorFlow 功能函数

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }