1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| import tensorflow as tf
var1=tf.constant([[11,12], [21,22]], tf.float32)
''' [[11. 12.] [21. 22.]] '''
var2=tf.zeros([2,2],tf.float32)
''' [[0. 0.] [0. 0.]] '''
var3=tf.ones([2,2],tf.float32)
''' [[1. 1.] [1. 1.]] '''
var4=tf.zeros_like([[11,12], [21,22]],tf.float32)
''' [[0. 0.] [0. 0.]] '''
var5=tf.ones_like([[11,12], [21,22]],tf.float32)
''' [[1. 1.] [1. 1.]] '''
var6=tf.fill([3,3], 3.14)
''' [[3.14 3.14 3.14] [3.14 3.14 3.14] [3.14 3.14 3.14]] '''
var7=tf.random_normal([2,2], mean=0.0, stddev=1.0, dtype=tf.float32, seed=99)
''' [[-0.9496492 0.7335231] [-1.2504681 -1.5407863]] '''
with tf.Session() as s: s.run(tf.global_variables_initializer()) print(s.run(var1),s.run(var2),s.run(var3),s.run(var4),s.run(var5),s.run(var6),s.run(var7),sep="\n")
|