-
Notifications
You must be signed in to change notification settings - Fork 0
/
second-tensorflow.py
129 lines (87 loc) · 3 KB
/
second-tensorflow.py
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import numpy as np
import tensorflow as tf
'''
# constant 1D tensor (vector)
a = tf.constant([2, 2], name="vector")
# constant 2x2 tensor (matrix)
b = tf.constant([[0, 1], [2, 3]], name="b")
# create a tensor of shape and all elements are 0s
a = tf.zeros([2, 3], tf.int32)
with tf.Session as session:
writer = tf.summary.FileWriter('./graphs', session.graph)
print(session.run(a))
writer.close()
'''
# _____________________________________________________________
# ====================== zeros ======================
"""
input_tensor = [[0, 1], [2, 3], [4, 5]]
a = tf.zeros_like(input_tensor, name="input_tensor")
with tf.Session() as session:
writer = tf.summary.FileWriter('./graphs', session.graph)
print(session.run(a))
writer.close()
"""
# _____________________________________________________________
# ====================== ones ======================
'''
a = tf.ones([2, 3], tf.int32)
input_tensor = [[0, 1], [2, 3]]
b = tf.ones_like(input_tensor)
with tf.Session() as session:
writer = tf.summary.FileWriter('./graphs', session.graph)
print(session.run(a))
print(session.run(b))
writer.close()
'''
# _____________________________________________________________
# ====================== fill ======================
'''
a = tf.fill([2,3], 8)
with tf.Session() as session:
writer = tf.summary.FileWriter('./graphs', session.graph)
print(session.run(a))
writer.close()
'''
# ______________________________________________________________
# ====================== linespace ======================
"""
a = tf.linspace(10.0, 13.0, 4, name="linespace")
with tf.Session() as session:
writer = tf.summary.FileWriter('./graphs', session.graph)
print(session.run(a))
writer.close()
"""
# ______________________________________________________________
# ====================== range ======================
'''
# start = 3, limit = 18, delta = 3
a = tf.range(3, 18, 3)
b = tf.range(3, 1, -0.5)
# limit = 5
c = tf.range(5)
with tf.Session() as session:
writer = tf.summary.FileWriter('./graphs', session.graph)
print(session.run(a), session.run(b), session.run(c))
writer.close()
'''
# ______________________________________________________________
# ====================== zeros ======================
# unlike numpy or py sequence, TensorFlow sequences are not iterable
'''
for x in np.linspace(0, 10, 5):
print(x)
with tf.Session() as session:
writer = tf.summary.FileWriter('./graphs', session.graph)
for x in tf.linspace(0, 10, 4):
print(session.run(x))
writer.close()
'''
# ______________________________________________________________
# ====================== random constants ======================
a = tf.random_normal([2, 2], mean=0, stddev=1, dtype=tf.float32)
b = tf.truncated_normal([2,2], mean=0, stddev=1, dtype=tf.float32)
c = tf.random_uniform([2,2], minval=0, maxval=None, dtype=tf.float32)
d = tf.random_shuffle([12, 35, 64, 5, 16])
with tf.Session() as session:
print(session.run(a), session.run(b), session.run(c), session.run(d))