Operation of simulation neural network for tensor operation

Source: Internet
Author: User

1Import TensorFlow asTF2Import NumPy asNP3Ts_norm=tf.random_normal ([ +])4With TF. Session () asSess:5Norm_data=Ts_norm.eval ()6Print (norm_data[:5])7Import Matplotlib.pyplot asPLT8 plt.hist (norm_data)9 plt.show ()Tendef layer_debug (output_dim,input_dim,inputs,activation=None): Onew=TF. Variable (Tf.random_normal ([Input_dim,output_dim])) AB=TF. Variable (Tf.random_normal ([1, Output_dim])) -Xwb=tf.matmul (INPUTS,W) +b -     ifActivation isNone: theoutputs=XWb -     Else: -outputs=activation (XWB) -     returnoutputs,w,b +X=tf.placeholder ("float", [None,4]) -H,w1,b1=layer_debug (output_dim=3, input_dim=4, inputs=X, +activation=Tf.nn.relu) AY,w2,b2=layer_debug (output_dim=2, input_dim=3, inputs=h) atWith TF. Session () asSess: -init=Tf.global_variables_initializer () - Sess.run (init) -X_array=np.array ([[0.4,0.2,0.4,0.5]]) -(LAYER_X,LAYER_H,LAYER_Y,W1,W2,B1,B2) =sess.run ((X,H,Y,W1,W2,B1,B2), feed_dict={X:x_array}) -Print'input layer x:');p rint (layer_x) inPrint'W1:');p rint (W1) -Print'B1:');p rint (B1) toPrint'input layer H:');p rint (layer_h) +Print'W2:');p rint (W2) -Print'B2:');p rint (B2) thePrint'input layer y:');p rint (layer_y)

Operation Result:

Operation of simulation neural network for tensor operation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.