Demo entry 6719034

Task2 and Task3

   

Submitted by anonymous on Mar 08, 2018 at 04:40
Language: Python 3. Code size: 1.1 kB.

# -*- coding: utf-8 -*-
"""
Created on Thu Feb  8 20:04:50 2018

@author: 17076991G
"""

import numpy as np
import tensorflow as tf

w = tf.Variable(tf.random_normal([6,10], stddev=0.1),name="a")
b= tf.constant([0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1],name="b")

r = ary_3=np.arange(1,61).reshape(10,6)
#tensor_b = tf.convert_to_tensor(r)
#tensor_c = tf.reshape(tensor_b, ([10,6]))

x=tf.placeholder(tf.float32,name="c")
y = tf.matmul(x,w)+b
init = tf.global_variables_initializer()
with tf.Session() as sess:
    sess.run(init)
    res = sess.run(y,feed_dict={x: r})
    print("res=", res)
    print("\n")
    
tensor_res = tf.convert_to_tensor(res)
print("eval=", tensor_res.eval())
    
sess= tf.InteractiveSession()
print("eval=", res.eval())
    
ply=tf.placeholder(tf.float32,name="ply")
loss = tf.sqrt(tf.reduce_mean(tf.square(tf.subtract(ply, y))))

with tf.Session() as sess3:
    L=sess3.run(loss,feed_dict={ply:[[[2.1],[1.5],[0.3],[1.2],[0.9],[2.4],[0.1],[0.8],[1.7],[1.8]]],y:res})
    print("loss=", L)

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).