構(gòu)造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.

參考指南:數(shù)學(xué)函數(shù)>矩陣數(shù)學(xué)函數(shù)

利用上述函數(shù)就可以在 TensorFlow 中構(gòu)造一個(gè)單位矩陣.

# 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.]]

參數(shù):

  • num_rows:非負(fù)的 int32 標(biāo)量張量,給出每個(gè)批處理矩陣中的行數(shù).
  • num_columns:(可選)非負(fù)的 int32 標(biāo)量張量,給出每個(gè)批處理矩陣中的列數(shù);默認(rèn)為 num_rows.
  • batch_shape:int 32 張量.如果提供,返回的張量將具有該形狀的主要批次維度.
  • dtype:生成的張量的元素類型.
  • name:該操作的名字;默認(rèn)為“eye”.

返回值:

形狀為 batch_shape + [num_rows, num_columns] 的張量.


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)