tensorflow一些常用函数的使用注意

tf.abs()  求tensor中数据的绝对值

tf.sign()  每一个数据都执行sigmod函数,得到对应的数值

tf.reduce_sum()  对不同维度数据求和。注意:1:求和每一行  0:求和每一列

tf.cast()  数值转换

 演示:

1 def mytest_split():
2     A = tf.truncated_normal(shape=[5,6], dtype=tf.float32)
3     used = tf.sign(tf.abs(A))
4     length = tf.reduce_sum(used, reduction_indices=1)
5     with tf.Session() as sess:
6         print(sess.run([A, used, length]))
7         print(A, used, length)

输出:

原文地址:https://www.cnblogs.com/demo-deng/p/10155939.html