codecamp

TensorFlow如何返回对角线

tf.diag_part

diag_part ( 
    input , 
    name = None
 )

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

返回张量的对角线部分.
此操作返回输入的对角线部分的张量.对角部分计算方法如下:
假设输入(input)具有维度:[D1,..., dk, D1,..., dk],那么输出是一个秩为 k 的张量,并且其维度为:[D1,..., dk] :

diagonal[i1,..., ik] = input[i1, ..., ik, i1,..., ik]

例如:

# 'input' is [[1, 0, 0, 0]
              [0, 2, 0, 0]
              [0, 0, 3, 0]
              [0, 0, 0, 4]]

tf.diag_part(input) ==> [1, 2, 3, 4]

ARGS:

  • input:一个张量.必须是下列类型之一:float32,float64,int32,int64,complex64,complex128.秩为 k 的张量的取值是 2, 4, 或6.
  • name:操作的名称(可选).

返回:

返回张量.与 input 具有相同的类型,为提取的对角线.

使用diag返回对角张量
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; }