zoukankan      html  css  js  c++  java
  • 吴裕雄--天生自然TensorFlow2教程:数据统计

    import tensorflow as tf
    
    a = tf.ones([2, 2])
    a
    tf.norm(a)
    tf.sqrt(tf.reduce_sum(tf.square(a)))
    a = tf.ones([4, 28, 28, 3])
    a.shape
    tf.norm(a)
    tf.sqrt(tf.reduce_sum(tf.square(a)))
    b = tf.ones([2, 2])
    tf.norm(b)
    tf.norm(b, ord=2, axis=1)
    tf.norm(b, ord=1)
    # 列为整体
    tf.norm(b, ord=1, axis=0)
    # 行为整体
    tf.norm(b, ord=1, axis=1)
    reduce,操作可能会有减维的功能,如[2,2],对行求max,会变成[2]
    a = tf.random.normal([4, 10])
    tf.reduce_min(a), tf.reduce_max(a), tf.reduce_mean(a)
    # 对某一行求max
    tf.reduce_min(a, axis=1), tf.reduce_max(a, axis=1), tf.reduce_mean(a, axis=1)
    a.shape
    tf.argmax(a).shape
    # 返回index
    tf.argmax(a)
    # 对第1维作用
    tf.argmin(a).shape
    # 对第2维作用
    tf.argmin(a, axis=1).shape
    a = tf.constant([1, 2, 3, 2, 5])
    b = tf.range(5)
    tf.equal(a, b)
    res = tf.equal(a, b)
    # 对True和False转换为1和0
    tf.reduce_sum(tf.cast(res, dtype=tf.int32))
    a = tf.random.normal([2, 3])
    a
    pred = tf.cast(tf.argmax(a, axis=1), dtype=tf.int32)
    pred.shape
    y = tf.constant([2, 1])
    y
    tf.equal(y, pred)
    correct = tf.reduce_sum(tf.cast(tf.equal(y, pred), dtype=tf.int32))
    correct
    correct / 2
    用于去重
    a = tf.range(5)
    a
    # 返回索引
    tf.unique(a)
    a = tf.constant([4, 2, 2, 4, 3])
    a
    res = tf.unique(a)
  • 相关阅读:
    iOS6和iOS7代码的适配(5)——popOver
    es5创建对象与继承
    js学习日记-new Object和Object.create到底干了啥
    js滚动及可视区域的相关的操作
    css匹配规则及性能
    normalize.css源码分析
    css的水平居中和垂直居中总结
    js快速排序算法
    数据结构flash演示
    二叉树遍历
  • 原文地址:https://www.cnblogs.com/tszr/p/12133208.html
Copyright © 2011-2022 走看看