微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

tensorflow

import tensorflow as tf
import numpy as np

 

1.tf.placeholder

  placeholder()函数是在神经网络构建graph的时候在模型中的占位,此时并没有把要输入的数据传入模型,它只会分配必要的内存

  等建立session,在会话中,运行模型的时候通过Feed_dict()函数向占位符喂入数据。

2.tf.session

1.tf.multiply 点乘

      input1 = tf.placeholder(tf.float32)

      input2 = tf.placeholder(tf.float32)

      output = tf.multiply(input1, input2)

     with tf.Session() as sess:
     print(sess.run(output, Feed_dict = {input1:[3.], input2: [4.]}))  --[12.]

 

2.tf.matmul 矩阵相乘

   x = tf.placeholder(tf.float32, shape=(3, 3))
   y = tf.matmul(x, x)

  with tf.Session() as sess:
  #print(sess.run(y)) # ERROR:此处x还没有赋值
  rand_array = np.random.rand(3, 3)
  print("rand_array",rand_array)
  print(sess.run(y, Feed_dict={x: rand_array}))

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐