tensorflow:大于阈值置1,小于置0
tensorflow
一个面向所有人的开源机器学习框架
项目地址:https://gitcode.com/gh_mirrors/te/tensorflow

·
看了 UeFan写的tensorflow tf.where使用方法,大于某个值为1,小于为0文章,依然有些模糊,自己结合实际注解了一下。
a=tf.random.uniform([2,2]) #随机生成2*2矩阵a
one = tf.ones_like(a) #生成与a大小一致的值全部为1的矩阵
zero = tf.zeros_like(a)
label = tf.where(a <0.5, x=zero, y=one) #0.5为阈值
得到结果:
tensorflow
一个面向所有人的开源机器学习框架
项目地址:https://gitcode.com/gh_mirrors/te/tensorflow
a: tf.Tensor(
[[0.25626993 0.53764176]
[0.27858937 0.92834556]], shape=(2, 2), dtype=float32)
label: tf.Tensor(
[[0. 1.]
[0. 1.]], shape=(2, 2), dtype=float32)
在numpy中:
threshold=0.5
x = np.where(pred < threshold, 0, 1) #数值小于0.5置0,大于0.5置1
推荐内容




一个面向所有人的开源机器学习框架
最近提交(Master分支:2 个月前 )
4f64a3d5
Instead, check for this case in `ResolveUsers` and `ResolveOperand`, by querying whether the `fused_expression_root` is part of the `HloFusionAdaptor`.
This prevents us from stepping into nested fusions.
PiperOrigin-RevId: 724311958
2 个月前
aa7e952e
Fix a bug in handling negative strides, and add a test case that exposes it.
We can have negative strides that are not just -1, e.g. with a combining
reshape.
PiperOrigin-RevId: 724293790
2 个月前
更多推荐
热门开源项目
活动日历
查看更多
直播时间 2025-04-23 19:00:00

GitTalk:国内首个微服务编排框架Juggle实战解析
直播时间 2025-04-22 18:31:56

字节AI 黑科技!从 Manus Agent 入门 Eino
直播时间 2025-04-09 14:34:18

樱花限定季|G-Star校园行&华中师范大学专场
直播时间 2025-04-07 14:51:20

樱花限定季|G-Star校园行&华中农业大学专场
直播时间 2025-03-26 14:30:09

开源工业物联实战!
所有评论(0)