tf.constant


tf.constant

constant(
    value,
    dtype=None,
    shape=None,
    name='Const',
    verify_shape=False
)

功能說明:

根據 value 的值生成一個 shape 維度的常量張量

參數列表:

參數名 必選 類型 說明
value 常量數值或者 list 輸出張量的值
dtype dtype 輸出張量元素類型
shape 1 維整形張量或 array 輸出張量的維度
name string 張量名稱
verify_shape Boolean 檢測 shape 是否和 value 的 shape 一致,若為 Fasle,不一致時,會用最后一個元素將 shape 補全

 

#!/usr/bin/python

import tensorflow as tf
import numpy as np
a = tf.constant([1,2,3,4,5,6],shape=[2,3])
b = tf.constant(-1,shape=[3,2])
c = tf.matmul(a,b)

e = tf.constant(np.arange(1,13,dtype=np.int32),shape=[2,2,3])
f = tf.constant(np.arange(13,25,dtype=np.int32),shape=[2,3,2])
g = tf.matmul(e,f)
with tf.Session() as sess:
    print (sess.run(a))
    print ("##################################")
    print (sess.run(b))
    print ("##################################")
    print (sess.run(c))
    print ("##################################")
    print (sess.run(e))
    print ("##################################")
    print (sess.run(f))
    print ("##################################")
    print (sess.run(g))

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM