TensorFlow2.0:数据统计
**
一 tf.norm( )函数–求范数
**
In [30]: a = tf.ones([2,2]) In [31]: tf.norm(a)#求a的二范数
Out[31]: <tf.Tensor: id=57, shape=(), dtype=float32, numpy=2.0>In [32]: tf.sqrt(tf.reduce_sum(tf.square(a)))#求a的二范数
Out[32]: <tf.Tensor: id=62, shape=(), dtype=float32, numpy=2.0>In [33]: a = tf.ones([4,28,28,3]) In [34]: tf.norm(a)
Out[34]: <tf.Tensor: id=71, shape=(), dtype=float32, numpy=96.99484>In [35]: tf.sqrt(tf.reduce_sum(tf.square(a)))#求a的二范数
Out[35]: <tf.Tensor: id=76, shape=(), dtype=float32, numpy=96.99484>
In [36]: b = tf.ones([2,2]) In [37]: tf.norm(b)
Out[37]: <tf.Tensor: id=85, shape=(), dtype=float32, numpy=2.0>In [38]: tf.norm(b,ord=2,axis=1)#求b在轴1方向的二范数
Out[38]: <tf.Tensor: id=91, shape=(2,), dtype=float32, numpy=array([1.4142135, 1.4142135], dtype=float32)>In [39]: tf.norm(b,ord=1)#求b的一范数
Out[39]: <tf.Tensor: id=96, shape=(), dtype=float32, numpy=4.0>In [40]: tf.norm(b,ord=1,axis=0)#求b在轴0方向上的一范数
Out[40]: <tf.Tensor: id=101, shape=(2,), dtype=float32, numpy=array([2., 2.], dtype=float32)>In [41]: tf.norm(b,ord=1,axis=1)#求b在轴1方向上的一范数
Out[41]: <tf.Tensor: id=106, shape=(2,), dtype=float32, numpy=array([2., 2.], dtype=float32)>
**
二 tf.reduce_min/max/mean( )函数–求解最小值最大值和均值函数
**
In [2]: a = tf.random.normal([4,10]) In [3]: tf.reduce_min(a)
Out[3]: <tf.Tensor: id=7, shape=(), dtype=float32, numpy=-1.8195488>In [4]: tf.reduce_max(a)
Out[4]: <tf.Tensor: id=10, shape=(), dtype=float32, numpy=2.3925323>In [5]: tf.reduce_mean(a)
Out[5]: <tf.Tensor: id=13, shape=(), dtype=float32, numpy=0.17027304>In [6]: tf.reduce_min(a,axis=1)#对轴1方向取最小值
Out[6]: <tf.Tensor: id=16, shape=(4,), dtype=float32, numpy=array([-0.3108449, -1.4913915, -1.3940301, -1.8195488], dtype=float32)>In [7]: tf.reduce_max(a,axis=1)#对轴1方向取最大值
Out[7]: <tf.Tensor: id=19, shape=(4,), dtype=float32, numpy=array([1.9342865, 0.8926946, 2.3925323, 1.7844682], dtype=float32)>In [8]: tf.reduce_mean(a,axis=1)#对轴1方向取均值
Out[8]: <tf.Tensor: id=22, shape=(4,), dtype=float32, numpy=array([ 0.7435825 , -0.08960855, 0.25611132, -0.2289931 ], dtype=float32)>
**
三 tf.argmax( )和tf.argmin( )函数-求最大最小值位置
**
In [9]: a = tf.random.normal([4,10]) In [10]: tf.argmax(a).shape
Out[10]: TensorShape([10])In [11]: tf.argmax(a)
Out[11]: <tf.Tensor: id=33, shape=(10,), dtype=int64, numpy=array([1, 0, 0, 1, 3, 3, 1, 1, 2, 0])>In [12]: tf.argmin(a).shape
Out[12]: TensorShape([10])In [13]: tf.argmin(a)
Out[13]: <tf.Tensor: id=38, shape=(10,), dtype=int64, numpy=array([3, 3, 2, 0, 2, 2, 0, 2, 0, 1])>In [14]: tf.argmax(a,axis=1)
Out[14]: <tf.Tensor: id=41, shape=(4,), dtype=int64, numpy=array([0, 0, 8, 4])>In [15]: tf.argmin(a,axis=1)
Out[15]: <tf.Tensor: id=44, shape=(4,), dtype=int64, numpy=array([6, 9, 4, 1])>
**
四 tf.equal( )函数
**
In [22]: a = tf.constant([0,2,3,2,4]) In [23]: b = tf.range(5) In [24]: res = tf.equal(a,b) In [25]: a,b,res
Out[25]:
(<tf.Tensor: id=55, shape=(5,), dtype=int32, numpy=array([0, 2, 3, 2, 4], dtype=int32)>,<tf.Tensor: id=59, shape=(5,), dtype=int32, numpy=array([0, 1, 2, 3, 4], dtype=int32)>,<tf.Tensor: id=60, shape=(5,), dtype=bool, numpy=array([ True, False, False, False, True])>)In [26]: tf.reduce_sum(tf.cast(res,dtype=tf.int32))
Out[26]: <tf.Tensor: id=66, shape=(), dtype=int32, numpy=2>
求解准确度
In [34]: a = tf.constant([[0.1,0.2,0.7],[0.9,0.05,0.05],[0.1,0.8,0.1],[0.01,0.99,0]]) In [35]: pred = tf.cast(tf.argmax(a,axis=1),dtype=tf.int32) In [36]: a,pred
Out[36]:
(<tf.Tensor: id=78, shape=(4, 3), dtype=float32, numpy=array([[0.1 , 0.2 , 0.7 ],[0.9 , 0.05, 0.05],[0.1 , 0.8 , 0.1 ],[0.01, 0.99, 0. ]], dtype=float32)>,<tf.Tensor: id=81, shape=(4,), dtype=int32, numpy=array([2, 0, 1, 1], dtype=int32)>)In [37]: y = tf.constant([2,0,1,2])
In [39]: correct_num = tf.reduce_sum(tf.cast(tf.equal(pred,y),dtype=tf.int32)) In [40]: accuracy = correct_num /a.shape[0] In [41]: correct_num,accuracy
Out[41]:
(<tf.Tensor: id=92, shape=(), dtype=int32, numpy=3>,<tf.Tensor: id=96, shape=(), dtype=float64, numpy=0.75>)
**
五 tf.unique( )函数-找不重复部分
**
In [42]: a = tf.range(5) In [43]: Unique,idx = tf.unique(a) In [44]: Unique,idx
Out[44]:
(<tf.Tensor: id=103, shape=(5,), dtype=int32, numpy=array([0, 1, 2, 3, 4], dtype=int32)>,<tf.Tensor: id=104, shape=(5,), dtype=int32, numpy=array([0, 1, 2, 3, 4], dtype=int32)>)In [45]: a = tf.constant([4,2,2,4,3]) In [46]: Unique,idx = tf.unique(a) In [47]: Unique,idx
Out[47]:
(<tf.Tensor: id=108, shape=(3,), dtype=int32, numpy=array([4, 2, 3], dtype=int32)>,<tf.Tensor: id=109, shape=(5,), dtype=int32, numpy=array([0, 1, 1, 0, 2], dtype=int32)>)In [48]: aa = tf.gather(Unique,idx) In [49]: aa
Out[49]: <tf.Tensor: id=113, shape=(5,), dtype=int32, numpy=array([4, 2, 2, 4, 3], dtype=int32)>
TensorFlow2.0:数据统计相关推荐
- Tensorflow2.0数据和部署(二)——基于设备的模型与TensorFlow Lite
文章目录 一.概述 1.模型存储 2.量化方法 3.模型验证 二.基于安卓的TF模型 1.初始化解释器 2.准备输入 3.调用解释器 4.输出结果 三.基于IOS的TF模型 1.初始化 2.准备输入 ...
- Tensorflow2.0数据和部署(一)——基于浏览器的模型与TensorFlow.js
文章目录 一.总体介绍 编程实践 1.创建一个简单的网页 2.编写脚本文件加载TensorFlow.js 3.完整代码 4.从csv文件中读取数据 5.设计更复杂的神经网络 二.图像分类 1.编写一个 ...
- TensorFlow2.0:数据的填充与复制
** 一 tf.pad( )填充函数 ** tf.pad(tensor, paddings, mode="CONSTANT", name=None, constant_values ...
- Tensorflow2.0数据和部署(四)——Tensorflow高级模型部署
文章目录 一.TF Serving 1.安装 2.搭建服务 (1)构建模型 (2)保存模型 (3)运行TF Model Server 3.使用服务 (1)将数据传递给服务器 (2)从服务器获取结果 二 ...
- Tensorflow2.0数据和部署(三)——基于Tensorflow数据服务的数据管道
文章目录 一.概述 1.概述 2.TFDS功能介绍 (1)ETL原理 (2)Datasetinfo (3)load参数说明 二.split和slice 1.Split API (1)Legacy AP ...
- 【TensorFlow2.0】(6) 数据统计,范数、最值、求和、均值、最值位置、唯一值、张量比较
各位同学好,今天和大家分享一下TensorFlow2.0中的数据分析操作.内容有: (1)范数 tf.norm():(2)最值 tf.reduce_min(), tf.reduce_max()(3)求 ...
- 【CTR模型】TensorFlow2.0 的 DeepFM 实现与实战(附代码+数据)
CTR 系列文章: 广告点击率(CTR)预测经典模型 GBDT + LR 理解与实践(附数据 + 代码) CTR经典模型串讲:FM / FFM / 双线性 FFM 相关推导与理解 CTR深度学习模型之 ...
- tensorflow2.0中valid_data的作用是在训练的过程对对比训练数据与测试数据的准确率 损失率,便于判断模型的训练效果:是过拟合还是欠拟合(过拟合)
tensorflow2.0中valid_data的作用是在训练的过程对对比训练数据与测试数据的准确率,便于判断模型的训练效果:是过拟合还是欠拟合 过拟合:训练数据的准确率较高而测试数据的准确率较低 欠 ...
- 利用TensorFlow2.0为胆固醇、血脂、血压数据构建时序深度学习模型(python完整源代码)
背景数据描述 胆固醇.高血脂.高血压是压在广大中年男性头上的三座大山,如何有效的监控他们,做到早发现.早预防.早治疗尤为关键,趁着这个假期我就利用TF2.0构建了一套时序预测模型,一来是可以帮我预发疾 ...
最新文章
- 「3D视觉从入门到精通」知识星球
- accesskey 提交
- 词云制作 Python
- ACM公选课第四节高精度 2020.4.9课-2020.4.10补
- 【SPFA】重建道路(jzoj 1212)
- 关于计算机书籍的收集与整理(一)
- 在视觉任务上大幅超越ReLU的新型激活函数
- macbook pro touch bar卡死的解决方法
- 计算机原理与技术索引的应用,经常学一点计算机底层原理系列之索引
- python自动化测试-基于 Python 的接口自动化测试实例
- oracle 10g 安装步骤
- MCS-51单片机的中断系统
- 初级商业数字营销师直通车题库
- 考虑一个包含n个元素的普通二叉最小堆数据结构,它支持最坏情况时间代价为O(lgn)的操作INSERT和EXTRACT-MIN。请给出一个势函数Φ,使得INSERT的平摊代价为O(lgn),EXTRAC
- MacBook安装双系统多分区共享访问解决方案
- 京东云mysql镜像_京东云数据库RDS SQL Server高可用概述
- 机遇与财富并存,一家网吧打造自己的客户数据库,后端疯狂盈利!
- 多包管理工具Lerna(莱尔纳)
- 批处理登陆邮箱代码分析
- Hive MetaStore服务增大内存
热门文章
- 博客园的博客中插入公式
- nodejs实战《一起学 Node.js》 使用 Express + MongoDB 搭建多人博客
- linux中的管道和重定向
- 我和Django那些事儿(8)----相册django插件photologue,jQuery插件Slides
- Java Redis 做分布式锁
- python运算学习之Numpy ------ 数组操作:连接数组、拆分数组 、广播机制、结构化数组、文件贮存与读写、np.where、数组去重...
- 中国剩余定理-模版(互质版)
- 机器学习定义及常用算法
- activiti驳回、沟通、转办的解决方法
- explorer.exe中发生未处理的win32异常