tensorflow使用

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

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

3、创建一个矩阵:

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

4、矩阵运算

点乘:

1 tf.matmul(W, X)

相加:可以直接用加号

5、计算代价函数

扫描二维码关注公众号,回复: 4832851 查看本文章
1 cost = tf.nn.sigmoid_cross_entropy_with_logits(logits = z, labels = y)

猜你喜欢

转载自www.cnblogs.com/lxc1910/p/10241317.html