TensorFlow常见函数解析

目录

1、tf.slice
2、tf.reshape
3、tf.transpose
4、tf.cast
5、tf.argmax
6、tf.truncated_normal
7、tf.nn.conv2d
8、tf.nn.softmax
9、tf.reduce_sum/tf.reduce_mean

1、tf.slice(input, begin, slice_dimension)

····
import tensorflow as tf
a = tf.constant([[1, 2, 3], [-1, -2, -2], [3, 2, 1]])
sess = tf.InteractiveSession()
b = tf.slice(a, [1, 0], [2, 3])
#[1, 0]表示从矩阵的[1, 0]开始计算截取位置
#注:由于是二维矩阵,所以此时只能填充二维数组
#[2, 3]表示在[1, 0]的基准位置取2行三列元素
sess.run(a)
sess.run(b)
'''
array([[ 1,  2,  2],
   [-1, -2, -3],
   [ 3,  2,  1]])
array([[-1, -2, -3],
   [ 3,  2,  1]])
'''
····

2、tf.reshape(input, shape)

注:shape为待转换的矩阵形状,其参数具体根据输入确定。并且其中有且仅允许存在一个‘-1’,表示在该维度上由计算机得出。并且在shape中的元素值乘积等于输入矩阵个数,且shape中元素的个数为输出数组维度

import tensorflow as tf
a = tf.constant([[1, 2, 3, 4], [4, 3, 2, 1]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值