线性函数
[python] view plain copy
def linear_function():
np.random.seed(1)
X = tf.constant(np.random.randn(3,1),name='X')
W = tf.constant(np.random.randn(4,3),name='W')
b = tf.constant(np.random.randn(4,1),name='b')
Y = tf.add(tf.matmul(W,X),b)
a = tf.constant(2)
sess = tf.Session()
result = sess.run(Y)
sess.close()
return result
print(str(linear_function()))
sigmoid函数
[python] view plain copy
def sigmoid(z):
x = tf.placeholder(tf.float32,name = "x")
sigmoid = tf.sigmoid(x)
with tf.Session() as sess:
result = sess.run(sigmoid,feed_dict = {x:z})
return result
print(sigmoid(2))