1、

1 a = tf.constant(2)
2 b = tf.constant(10)
3 c = tf.multiply(a,b)
4 print(c)
输出:
Tensor("Mul:0", shape=(), dtype=int32)

应该加上:
1 sess = tf.Session()
2 print(sess.run(c))

输出:20

 2、placeholder使用

可以先声明变量在定义:

1 x = tf.placeholder(tf.int64, name = 'x') #tf.float32
2 print(sess.run(2 * x, feed_dict = {x: 3}))
3 sess.close()

输出:6

矩阵也可用上述方式声明。

或者:

1 X = tf.placeholder(tf.float32, shape = (n_x, None), name = "X")

3、创建一个矩阵:

1 X = tf.constant(np.random.randn(3,1), name = "X")

4、矩阵运算

点乘:

1 tf.matmul(W, X)

相加:可以直接用加号

5、计算代价函数

1 cost = tf.nn.sigmoid_cross_entropy_with_logits(logits = z, labels = y)

tensorflow使用

 


 
                    
            
                

相关文章:

  • 2021-07-30
  • 2021-09-15
  • 2021-07-16
  • 2021-06-24
  • 2021-05-26
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-26
  • 2022-02-02
  • 2021-05-30
  • 2021-10-28
  • 2021-10-01
  • 2021-08-28
相关资源
相似解决方案