码迷,mamicode.com
首页 > 其他好文 > 详细

tenserflow-0

时间:2017-07-18 01:44:25      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:ntop   square   and   nump   float   style   numpy   ble   pre   

 

import tensorflow as tf
import numpy as np


x_data = np.float32(np.random.rand(2, 100))
y_data = np.dot([0.100, 0.200], x_data) + 0.300


b = tf.Variable(tf.zeros([1]))
W = tf.Variable(tf.random_uniform([1, 2], -1.0, 1.0))
y = tf.matmul(W, x_data) + b


loss = tf.reduce_mean(tf.square(y - y_data))
optimizer = tf.train.GradientDescentOptimizer(0.5)
train = optimizer.minimize(loss)


init = tf.initialize_all_variables()


sess = tf.Session()
sess.run(init)


for step in xrange(0, 201):
    sess.run(train)
    if step % 20 == 0:
        print step, sess.run(W), sess.run(b)

 

tenserflow-0

标签:ntop   square   and   nump   float   style   numpy   ble   pre   

原文地址:http://www.cnblogs.com/kprac/p/7197932.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!