tensorflow2.0基本操作

Broadcasting (广播)

  • why?
    • 简洁
    • 省内存
  • Example
  •  

数学运算

outline
  • +-*/
  • **,pow,square
  • sqrt
  • //,%
  • exp,log
  • @,matmul
  • linear layer

合并与分割

  • tf.concat([],axis=)
    • 合并
    • 不会创建新维度
  • tf.stack([],axis=)
    • 合并
    • 会创建新维度
  • tf.unstack([],axis=)
    • 与tf.stack()是可逆的
  • tf.split([],axis=,num_or_size_splits=[])
    • num_or_size_splits:分割成什么样

数据统计

  • tf.norm([],ord=,axis=) # 张量范数
    • 二范数:平方和开根号
    • 一范数:绝对值的和
    • ord:1,2
  • tf.reduce_min/max/mean
  • tf.argmax/argmin
    • 返回最值的索引
  • tf.equal(a,b)
    • 作比较
  • tf.unique
    • 返回两tensor

数据排序

  • sort/argsort
    • tf.sort([],direction='')
    • tf.argsort :返回索引
  • top_k
    • tf.math.top_k()
    • 应用:top-k accuracy
  • top-5 acc.

填充与复制

  • tf.pad
    • 数据的填充
    • tf.pad(a,[1,1],[1,1])
  • tf.tile
    • 复制数据
    • tf.tile(a,[2,2])
  • broadcast_to

张量限幅

  • clip_by_value
    • tf.maximum(a,2)
    • tf.minimum(a,8)
    • tf.clip_by_value(a,2,8)
  • relu
  • clip_by_norm
  • gradient

高阶OP

  • where

猜你喜欢

转载自www.cnblogs.com/dhp-2016/p/11184213.html