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)

吴裕雄--天生自然TensorFlow2教程:数据统计的更多相关文章

  1. 吴裕雄--天生自然TensorFlow2教程:数据加载

    import tensorflow as tf from tensorflow import keras # train: 60k | test: 10k (x, y), (x_test, y_tes ...

  2. 吴裕雄--天生自然TensorFlow2教程:手写数字问题实战

    import tensorflow as tf from tensorflow import keras from keras import Sequential,datasets, layers, ...

  3. 吴裕雄--天生自然TensorFlow2教程:维度变换

    图片视图 [b, 28, 28] # 保存b张图片,28行,28列(保存数据一般行优先),图片的数据没有被破坏 [b, 28*28] # 保存b张图片,不考虑图片的行和列,只保存图片的数据,不关注图片 ...

  4. 吴裕雄--天生自然TensorFlow2教程:Tensor数据类型

    list: [1,1.2,'hello'] ,存储图片占用内存非常大 np.array,存成一个静态数组,但是numpy在深度学习之前就出现了,所以不适合深度学习 tf.Tensor,为了弥补nump ...

  5. 吴裕雄--天生自然TensorFlow2教程:函数优化实战

    import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D def himme ...

  6. 吴裕雄--天生自然TensorFlow2教程:反向传播算法

  7. 吴裕雄--天生自然TensorFlow2教程:链式法则

    import tensorflow as tf x = tf.constant(1.) w1 = tf.constant(2.) b1 = tf.constant(1.) w2 = tf.consta ...

  8. 吴裕雄--天生自然TensorFlow2教程:多输出感知机及其梯度

    import tensorflow as tf x = tf.random.normal([2, 4]) w = tf.random.normal([4, 3]) b = tf.zeros([3]) ...

  9. 吴裕雄--天生自然TensorFlow2教程:单输出感知机及其梯度

    import tensorflow as tf x = tf.random.normal([1, 3]) w = tf.ones([3, 1]) b = tf.ones([1]) y = tf.con ...

随机推荐

  1. Hive的原生部署方式

    一.Hive的部署 1.官方文档 https://cwiki.apache.org/confluence/display/Hive/GettingStarted 2.前提条件 需要安装JDK1.7之上 ...

  2. Ubuntu操作系统编译安装zabbix报错汇总

    Ubuntu操作系统编译安装zabbix报错汇总 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.报错提示:"configure: error: MySQL libra ...

  3. memset函数总结

    之前有一个程序栽在了memset函数上面,对memset函数一直耿耿于怀,于是想总结一下这个常用但是总出错的函数. memset在string.h文件中是这么定义的: void*代表这个函数的返回值可 ...

  4. 201705 Ruby基础拾遗

    Mixin override 异常处理 super 与super() 使用%()处理需要string interpolation但同时也需要" "(double quote)的状况 ...

  5. spingboot2.0外部引入xml配置文件时找不到文件等报错

    之前的项目可以启动,后面不知道为什么都不行了,报错如下: SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found bindin ...

  6. springCloud 之 Eureka服务治理

    服务治理是微服务架构中最核心和基础的模块 首先我们创建一个springCloud eureka service的springboot 工程,该工程提供一个服务中心,用来注册服务,第二个工程是clien ...

  7. 虚拟机上安装SVN服务

    服务器端安装SVN(centos)1.yum install subversion2.svn的相关配置1创建一个SVN仓库(所有项目存放与管理)mkdir -p /svndata/projects2. ...

  8. php二位数组排序(按子元素排序)

    array_multisort(array_column($mainTree[$note]["beCalls"], "wtp"), SORT_DESC, arr ...

  9. JAVA DateUtil 工具类封装(转)

    原文链接 https://blog.csdn.net/wangpeng047/article/details/8295623  作者三次整理后的代码 下载链接   https://www.lanzou ...

  10. 吴裕雄--天生自然java开发常用类库学习笔记:同步与死锁

    class MyThread implements Runnable{ private int ticket = 5 ; // 假设一共有5张票 public void run(){ for(int ...