codecamp

构造TensorFlow的单位矩阵

tf.eye

eye(
    num_rows,
    num_columns=None,
    batch_shape=None,
    dtype=tf.float32,
    name=None
)

定义在:tensorflow/python/ops/linalg_ops.py.

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

利用上述函数就可以在 TensorFlow 中构造一个单位矩阵.

# Construct one identity matrix.
tf.eye(2)
==> [[1., 0.],
     [0., 1.]]

# Construct a batch of 3 identity matricies, each 2 x 2.
# batch_identity[i, :, :] is a 2 x 2 identity matrix, i = 0, 1, 2.
batch_identity = tf.eye(2, batch_shape=[3])

# Construct one 2 x 3 "identity" matrix
tf.eye(2, num_columns=3)
==> [[ 1.,  0.,  0.],
     [ 0.,  1.,  0.]]

参数:

  • num_rows:非负的 int32 标量张量,给出每个批处理矩阵中的行数.
  • num_columns:(可选)非负的 int32 标量张量,给出每个批处理矩阵中的列数;默认为 num_rows.
  • batch_shape:int 32 张量.如果提供,返回的张量将具有该形状的主要批次维度.
  • dtype:生成的张量的元素类型.
  • name:该操作的名字;默认为“eye”.

返回值:

形状为 batch_shape + [num_rows, num_columns] 的张量.


如何在TensorFlow张量形状中插入维度
怎么对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; }