tensorflow基本操作《03矩陣基礎》補充

tensorflow基本操作《03矩陣基礎》補充

代碼

import tensorflow as tf
mat0=tf.constant([[0,0,0],[0,0,0]])
mat1=tf.zeros([2,3])
mat2=tf.ones([3,2])
mat3=tf.fill([3,2],15)
mat=tf.constant([[4],[5],[6]])
mat4=tf.zeros_like(mat)
mat5=tf.linspace(0.0,2.0,11)  # 平等分
mat6=tf.random_uniform([2,3],-1,2)  #隨機矩陣  數據範圍【-1,2】
with tf.Session() as sess:
    print(sess.run(mat0))
    print(sess.run(mat1))
    print(sess.run(mat2))
    print(sess.run(mat3))
    print(sess.run(mat4))
    print(sess.run(mat5))
    print(sess.run(mat6))

運行結果

[[0 0 0]
 [0 0 0]]
[[0. 0. 0.]
 [0. 0. 0.]]
[[1. 1.]
 [1. 1.]
 [1. 1.]]
[[15 15]
 [15 15]
 [15 15]]
[[0]
 [0]
 [0]]
[0.        0.2       0.4       0.6       0.8       1.        1.2
 1.4       1.6       1.8000001 2.       ]
[[-0.8736869  1.8987808  1.7991829]
 [ 1.8607564 -0.7534281  1.9443381]]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章