构造TensorFlow的单位矩阵

2018-10-16 17:42 更新

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] 的张量.


以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号