栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

tensorflow2.x 张量的数据统计

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

tensorflow2.x 张量的数据统计

@TOP

数据统计

▪ tf.norm
▪ tf.reduce_min/max
▪ tf.argmax/argmin
▪ tf.equal
▪ tf.unique

tf.norm

** 向量 norm**

# 向量 norm
a = tf.ones([2,2])
print(tf.norm(a))
print(tf.sqrt(tf.reduce_sum(tf.square(a))))

a = tf.ones([4,28,28,3])
print(tf.norm(a))
print(tf.sqrt(tf.reduce_sum(tf.square(a))))

二范数:

# 二范数
b = tf.ones([2,2])
print(b)
print(tf.norm(b))
print(tf.norm(b,ord=2,axis=1))
print(tf.norm(b,ord=1))
print(tf.norm(b,ord=1,axis=0))
print(tf.norm(b,ord=2,axis=1))

tf.norm(a) = tf.sqrt(tf.reduce_sum(tf.square(a)))

ord:指定做什么样的范数计算。
axis:默认为Non(向量)

tf.reduce_min/max

作用:求最大值、最小值、均值

#tf.reduce_?
a = tf.random.normal([4,10])
print(tf.reduce_min(a))
print(tf.reduce_max(a))
print(tf.reduce_mean(a))

print(tf.reduce_min(a,axis=1))
print(tf.reduce_max(a,axis=1))
print(tf.reduce_mean(a,axis=1))
tf.argmax/argmin

作用: 求最大值和最小值的位置

# argmax/argmin   axis 默认是0
a = tf.random.normal([4,10])
print(a)
print("tf.argmax(a)",tf.argmax(a))
print("tf.argmax(a).shape",tf.argmax(a).shape)
print("tf.argmin(a,axis=1)",tf.argmin(a,axis=1))
print("tf.argmin(a,axis=1).shape",tf.argmin(a,axis=1).shape)
tf.equal
# tf.equal
a = tf.constant([1,2,3,2,5])
b = tf.range(5)
res = tf.equal(a,b)
print(res)

#得到的是这个比较中间,相同元素的个数,其实是一个准确度的概念,真实值和预测值匹配个数
print(tf.reduce_sum(tf.cast(res,dtype=tf.int32)))
tf.unique
# tf.unique
a = tf.range(5)
print(a)
print(tf.unique(a))
a = tf.constant([4,2,2,4,3])
print(a)
print(tf.unique(a))
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/275916.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号