Torch学习记录

Tensorflow 各基础函数使用

tf.repeat(tensor, repeats, axis=0)重复维度,扩张Tensor数据

mu = tf.random.normal([1, 2, 3])
print(mu)
mu1 = tf.repeat(mu, repeats=4, axis=0)
print(mu1)
##结果:tf.Tensor(
[[[-2.2011704   1.6632527   1.052491  ]
  [-0.12369094  0.29675704 -1.5922679 ]]], shape=(1, 2, 3), dtype=float32)
tf.Tensor(
[[[-2.2011704   1.6632527   1.052491  ]
  [-0.12369094  0.29675704 -1.5922679 ]]

 [[-2.2011704   1.6632527   1.052491  ]
  [-0.12369094  0.29675704 -1.5922679 ]]

 [[-2.2011704   1.6632527   1.052491  ]
  [-0.12369094  0.29675704 -1.5922679 ]]

 [[-2.2011704   1.6632527   1.052491  ]
  [-0.12369094  0.29675704 -1.5922679 ]]], shape=(4, 2, 3), dtype=float32)

tf.transpose(tensor, [dimension_1, dimenaion_2,…,dimension_n]):这个函数主要适用于交换输入张量的不同维度用的,如果输入张量是二维,就相当是转置。输入张量是三维,可以强制更换维度。

mu = tf.random.normal([2, 2, 3])
print(mu)
mu1 = tf.transpose(mu, [0, 2, 1])
print(mu1)
# 结果:
tf.Tensor(
[[[ 0.6118678  -0.05129734 -1.2282405 ]
  [ 0.12983456 -0.7894752  -0.5745441 ]]

 [[ 0.7239799   0.3909837  -0.47409806]
  [ 1.4259791   0.526061    0.13551469]]], shape=(2, 2, 3), dtype=float32)
tf.Tensor(
[[[ 0.6118678   0.12983456]
  [-0.05129734 -0.7894752 ]
  [-1.2282405  -0.5745441 ]]

 [[ 0.7239799   1.4259791 ]
  [ 0.3909837   0.526061  ]
  [-0.47409806  0.13551469]]], shape=(2, 3, 2), dtype=float32)

torch : function.softmax(tensor, dim=0,1,2)

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值