【TF2.0】【笔记】TensorFlow数据类型基础2

Tensorflow进阶

合并与分割

合并

使用tf.concat (concatenate)合并张量,不会产生新的维度,合并操作可以在任意的维度上进行,唯一的约束是非合并维度的长度必须一致

使用tf.stack(stack)会产生新的维度,它需要所有合并的张量 shape 完全一致才可合并

a = tf.random.normal([4, 35, 8])
b = tf.random.normal([4, 35, 8])
c = tf.concat([a, b, b], axis = 1)
print(c.shape)
d = tf.stack([a, b], axis=0)
e = tf.stack([a, b], axis=-1)
print(f'd:{d.shape} e:{e.shape}')

分割

tf.split和tf.unstack

a = tf.random.normal([4, 35, 8])
r1 = tf.split(a, axis=0, num_or_size_splits=4)
r2 = tf.split(a, axis=1, num_or_size_splits=[30, 5])
r3 = tf.unstack(a)
print(type(r1))
print(tf.convert_to_tensor(r1).shape)
print(len(r2))
print(tf.convert_to_tensor(r3).shape)

split和unstack的返回值是list类型

数据统计

向量范数

向量范数(Vector norm)是表征向量“长度”的一种度量方法,在神经网络中,常用来表示张量的权值大小,梯度大小,下面是常见的范数:

在这里插入图片描述

x = tf.ones([2, 2])
print(tf.norm(x, ord=1))
print(tf.norm(x,
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值