tensorflow1.X常量

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)
#tf.constant(value, dtype, shape, name)
'''
[[11. 12.]
[21. 22.]]
'''

var2=tf.zeros([2,2],tf.float32)
#tf.zeros(shape, dtype, name)
'''
[[0. 0.]
[0. 0.]]
'''

var3=tf.ones([2,2],tf.float32)
#tf.ones(shape, dtype, name)
'''
[[1. 1.]
[1. 1.]]
'''

var4=tf.zeros_like([[11,12],
[21,22]],tf.float32)
#tf.zeros_like(tensor, dtype, name)
'''
[[0. 0.]
[0. 0.]]
'''

var5=tf.ones_like([[11,12],
[21,22]],tf.float32)
#tf.ones_like(tensor, dtype, name)
'''
[[1. 1.]
[1. 1.]]
'''

var6=tf.fill([3,3], 3.14)
#tf.fill(dims, value, name)
'''
[[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)
#tf.random_normal(shape, mean=0.0, stddev=1.0, dtype=tf.float32, seed=None, name=None)
'''
[[-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")

转载请注明来源 https://tianweiye.github.io