(9)tensorflow数据统计

数据统计

功能函数代码
范数计算tf.norm(x,ord)
最值tf.reduce_max(x,axis)、 tf.reduce_min(x,axis)
均值tf.reduce_mean(x,axis)
tf.reduce_sum(x,axis)
返回统计最值索引tf.argmax(x, axis),tf.argmin(x, axis)

范数

  • tf.norm(x,ord)
  • ord 指定为 1、 2 时计算 L1、 L2 范数,指定为 np.inf 时计算∞ −范数
  • L1范数:定义为向量𝒙的所有元素绝对值之和
  • L2范数:定义为向量𝒙的所有元素的平方和,再开根号
  • L3范数:定义为向量𝒙的所有元素的l立方和,再开立方根
  • ∞ (无穷大)范数,定义为向量𝒙的所有元素绝对值的最大值
import tensorflow as tf
import numpy as np
x = tf.ones([2,2])
print(tf.norm(x,ord=1))
print(tf.norm(x,ord=2))
print(tf.norm(x,ord=3))
print(tf.norm(x,ord=np.inf))


out:
tf.Tensor(4.0, shape=(), dtype=float32)
tf.Tensor(2.0, shape=(), dtype=float32)
tf.Tensor(1.587401, shape=(), dtype=float32)
tf.Tensor(1.0, shape=(), dtype=float32)

简单统计

  • tf.reduce_*(x,axis)
  • 当不指定 axis 参数时, tf.reduce_*函数会求解出全局元素的最大、最小、 均值、和等
    数据

最值

  • tf.reduce_max(x,axis)、 tf.reduce_min(x,axis)
  • 返回axis上的最值

均值

  • tf.reduce_mean(x,axis)
  • 返回axis上的最值

  • tf.reduce_sum(x,axis)
  • 返回axis上的最值

返回统计最值索引

  • tf.argmax(x, axis),tf.argmin(x, axis)
  • 可以求解在 axis 轴上, x 的最大值、 最小值所在的索引
import tensorflow as tf
x = tf.random.normal([4, 10])
print(x)
print(tf.reduce_max(x,axis=1))
print(tf.reduce_min(x,axis=1))
print(tf.reduce_sum(x,axis=1))
print(tf.reduce_mean(x,axis=1))
print(tf.argmax(x, axis=1))
print(tf.argmin(x, axis=1))


out:
tf.Tensor(
[[ 1.6965815   0.09555305  0.33692268 -0.7822668  -1.0054542  -1.334124
   0.7095199  -2.8712015   1.8947812  -0.48956573]
 [-0.56082326 -1.5098412   0.27639452  1.3449372  -2.0256445   1.2122011
   0.50152576  0.03570785  0.52847946  0.6525247 ]
 [ 1.6948462   0.56346595 -0.56629235  0.31268176  0.96957785  1.2716382
  -0.04530253  2.1147048   0.46754405  2.5528266 ]
 [-0.01668303 -1.3695923   0.12339069  0.8491427   0.55647653 -1.2386454
   1.9543849  -0.68476975  1.7511108  -0.31127346]], shape=(4, 10), dtype=float32)
tf.Tensor([1.8947812 1.3449372 2.5528266 1.9543849], shape=(4,), dtype=float32)
tf.Tensor([-2.8712015  -2.0256445  -0.56629235 -1.3695923 ], shape=(4,), dtype=float32)
tf.Tensor([-1.749254    0.45546162  9.3356905   1.6135417 ], shape=(4,), dtype=float32)
tf.Tensor([-0.1749254   0.04554616  0.9335691   0.16135417], shape=(4,), dtype=float32)
tf.Tensor([8 3 9 6], shape=(4,), dtype=int64)
tf.Tensor([7 4 2 1], shape=(4,), dtype=int64)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小蜗笔记

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值