Skip to content

Commit

Permalink
second-tensorflow: change comment type
Browse files Browse the repository at this point in the history
fourth-tensorflow: add tf.ones([2,2])...
  • Loading branch information
Thanirin committed Feb 10, 2019
1 parent e89f71a commit 0841aa4
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 68 deletions.
3 changes: 2 additions & 1 deletion fourth-tensorflow.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import tensorflow as tf
import numpy as np

# Python native types

t_0 = 19
t_1 = [b"apple", b"peach", b"grape"]

t_2 = [[True, False, False],
[False, False, False],
[False, True, False]]
Expand All @@ -15,6 +15,7 @@

print(session.run(tf.zeros_like(t_1)))
# print(session.run(tf.ones_like(t_1))) # expect string, got 1 (int) instead
print(session.run(tf.ones([2, 2], np.float32))) # or tf.float32 is Ok too

print(session.run(tf.zeros_like(t_2)))
print(session.run(tf.ones_like(t_2)))
148 changes: 81 additions & 67 deletions second-tensorflow.py
Original file line number Diff line number Diff line change
@@ -1,106 +1,120 @@
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()
'''
# 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()
"""
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()
'''
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()
'''
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()
"""
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()
'''
# 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)
'''
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))
# 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()
writer.close()
'''

# ______________________________________________________________

Expand Down

0 comments on commit 0841aa4

Please sign in to comment.