• 1.2 tensorflow2.0 常用函数


    a
    #<tf.Tensor: shape=(4, 2), dtype=float32, numpy=
    array([[ 0.491424  ,  0.6428182 ],
           [ 2.247138  ,  0.2008341 ],
           [ 0.93056387,  0.01603121],
           [ 0.33425295, -1.1971117 ]], dtype=float32)>
    tf.cast(a,dtype=tf.float64)
    a
    #<tf.Tensor: shape=(4, 2), dtype=float32, numpy=
    array([[ 0.491424  ,  0.6428182 ],
           [ 2.247138  ,  0.2008341 ],
           [ 0.93056387,  0.01603121],
           [ 0.33425295, -1.1971117 ]], dtype=float32)>
    tf.reduce_min(a)
    #<tf.Tensor: shape=(), dtype=float32, numpy=-1.1971117>
    tf.reduce_max(a)
    #<tf.Tensor: shape=(), dtype=float32, numpy=2.247138>
    
    #axis = 0 代表纵向,axis = 1 代表横向
    tf.reduce_mean(a)
    #<tf.Tensor: shape=(), dtype=float32, numpy=0.45824385>
    tf.reduce_mean(a,axis=0)
    #<tf.Tensor: shape=(2,), dtype=float32, numpy=array([ 1.0008447 , -0.08435705], dtype=float32)>
    tf.reduce_mean(a,axis=1)
    #<tf.Tensor: shape=(4,), dtype=float32, numpy=array([ 0.5671211 ,  1.223986  ,  0.47329754, -0.4314294 ], dtype=float32)>

    #tf.reduce_sum()同理
    tf.Varible
    tf.add,tf.substract,tf.multiply,tf.divide
    tf.square,tf.pow,tf.sqrt
    tf.matmul
    features = tf.constant([12,23,10,17]) 
    labels = tf.constant([0, 1, 1, 0]) 
    dataset = tf.data.Dataset.from_tensor_slices((features, labels)) 
    dataset
    #<TensorSliceDataset shapes: ((), ()), types: (tf.int32, tf.int32)>
    for i in dataset:
      print(i)
    (<tf.Tensor: shape=(), dtype=int32, numpy=12>, <tf.Tensor: shape=(), dtype=int32, numpy=0>)
    (<tf.Tensor: shape=(), dtype=int32, numpy=23>, <tf.Tensor: shape=(), dtype=int32, numpy=1>)
    (<tf.Tensor: shape=(), dtype=int32, numpy=10>, <tf.Tensor: shape=(), dtype=int32, numpy=1>)
    (<tf.Tensor: shape=(), dtype=int32, numpy=17>, <tf.Tensor: shape=(), dtype=int32, numpy=0>)
  • 相关阅读:
    IT 面试题
    elasticsearch学习(三):分布式
    es学习(二):elasticsearch 数据存储
    linux mysql 简单记录
    nginx 初了解
    dubbo 学习(一)
    关于通过angularJs将页面中的html table 导出生成excel
    postgresql编译安装与调试(二)
    postgresql编译安装与调试(一)
    说说shell脚本中的export 和 source,bash
  • 原文地址:https://www.cnblogs.com/gao-chao/p/13356043.html
Copyright © 2020-2023  润新知