吴裕雄--天生自然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)
吴裕雄--天生自然TensorFlow2教程:数据统计的更多相关文章
- 吴裕雄--天生自然TensorFlow2教程:数据加载
import tensorflow as tf from tensorflow import keras # train: 60k | test: 10k (x, y), (x_test, y_tes ...
- 吴裕雄--天生自然TensorFlow2教程:手写数字问题实战
import tensorflow as tf from tensorflow import keras from keras import Sequential,datasets, layers, ...
- 吴裕雄--天生自然TensorFlow2教程:维度变换
图片视图 [b, 28, 28] # 保存b张图片,28行,28列(保存数据一般行优先),图片的数据没有被破坏 [b, 28*28] # 保存b张图片,不考虑图片的行和列,只保存图片的数据,不关注图片 ...
- 吴裕雄--天生自然TensorFlow2教程:Tensor数据类型
list: [1,1.2,'hello'] ,存储图片占用内存非常大 np.array,存成一个静态数组,但是numpy在深度学习之前就出现了,所以不适合深度学习 tf.Tensor,为了弥补nump ...
- 吴裕雄--天生自然TensorFlow2教程:函数优化实战
import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D def himme ...
- 吴裕雄--天生自然TensorFlow2教程:反向传播算法
- 吴裕雄--天生自然TensorFlow2教程:链式法则
import tensorflow as tf x = tf.constant(1.) w1 = tf.constant(2.) b1 = tf.constant(1.) w2 = tf.consta ...
- 吴裕雄--天生自然TensorFlow2教程:多输出感知机及其梯度
import tensorflow as tf x = tf.random.normal([2, 4]) w = tf.random.normal([4, 3]) b = tf.zeros([3]) ...
- 吴裕雄--天生自然TensorFlow2教程:单输出感知机及其梯度
import tensorflow as tf x = tf.random.normal([1, 3]) w = tf.ones([3, 1]) b = tf.ones([1]) y = tf.con ...
随机推荐
- Matplotlib 图形绘制
章节 Matplotlib 安装 Matplotlib 入门 Matplotlib 基本概念 Matplotlib 图形绘制 Matplotlib 多个图形 Matplotlib 其他类型图形 Mat ...
- 2017 北京网络赛 E Cats and Fish
Cats and Fish 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 There are many homeless cats in PKU campus. They ...
- greenplum 存储过程 变量类型
参考: https://www.cnblogs.com/kungfupanda/p/4478917.html
- 学习进度-04 Scala的学习
在Scala中,主函数的定义是def main(args: Array[String]),Scala中必须使用对象方法 1.变量: Scala中的变量分为两种var和val. 例如:def main( ...
- 查看 Secret【转】
可以通过 kubectl get secret 查看存在的 secret. 显示有两个数据条目,kubectl describe secret 查看条目的 Key: 如果还想查看 Value,可以用 ...
- linux(centos6.9)下rpm方式安装mysql后mysql服务无法启动
以下两种方式启动都报错:启动失败: [root@node03 ~]# service mysqld startMySQL Daemon failed to start.Starting mysqld: ...
- poj 2576 Tug of War
还是神奇的随机算法,,(看视频说这是爬山法??) 其实就是把序列随机分成两半(我太弱,只知道random_shuffle),然后再每个序列里rand一个位置,x,y然后比较是不是交换之后是更优的. 然 ...
- .net core文件系统简介
在asp.net core程序中,我们可以通过如下代码开启对Web 根目录内的文件静态访问功能: app.UseStaticFiles(); 如果要提供更高级的选项,例如:将其它的物理文件夹下的文件作 ...
- 7.11 如何应用Varnish
动态数据缓存 Step 1 修改devault.vcl文件 # This ) # man page for details on VCL syntax and semantics. # # Defau ...
- 如何拯救被Due逼疯的留学生们?
Final季又到了,还有多少paper,多少project没完成?每年一到这个时候,手忙脚乱赶各种进度就成了留学小伙伴们共同的日常.任务多,不知道从何开始,拖延,烦躁……到底该怎么办?小编今天为各位介 ...