tensorflow的一些函数
生活随笔
收集整理的這篇文章主要介紹了
tensorflow的一些函数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.tf.constant(value,dtype=None,shape=None,name='Const')
注意這個函數創造的是一個常數tensor,而不是一個具體的常數
value:即可以是list,也可以是value
dtype:對應生成的tensor里的元素的類型
# Constant 1-D Tensor populated with value list.tensor = tf.constant([1, 2, 3, 4, 5, 6, 7]) => [1 2 3 4 5 6 7] 注意這種直接加入list的情況# Constant 2-D tensor populated with scalar value -1.tensor = tf.constant(-1.0, shape=[2, 3]) => [[-1. -1. -1.][-1. -1. -1.]]對于value給tensor,并不是不能shape形狀,如果shape出來value中的元素不夠用時,就以最后一個元素重復出現填充至滿足形狀。
以下實例:
>>> sess = tf.InteractiveSession()>>> a = tf.constant([1,2,3],shape = [6]) >>> b = tf.constant([1,2,3],shape = [3,2]) >>> c = tf.constant([1,2,3],shape = [2,3])>>> print sess.run(a) [1 2 3 3 3 3] >>> print sess.run(b) [[1 2][3 3][3 3]] >>> print sess.run(c) [[1 2 3][3 3 3]]?
?2.tf.truncated_normal(shape,mean=0.0,stddev=1.0,dtype=tf.float32,seed=None,name=None)
這個函數是從截斷的正態分布產生隨機數
mean:均值
stddev:標準差
轉載于:https://www.cnblogs.com/ymjyqsx/p/6530016.html
總結
以上是生活随笔為你收集整理的tensorflow的一些函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PHP 微信机器人 Vbot 结合 La
- 下一篇: 数据类型进阶