当前位置:网站首页>tensorflow scatter_nd函数
tensorflow scatter_nd函数
2022-07-24 05:50:00 【不负韶华ღ】
函数原型
tf.scatter_nd(
indices, updates, shape, name=None
)
函数说明
将张量updates的形状扩展到新的形状shape,张量在新形状shape中的坐标为indices,其他的元素值为0。
参数indices表示张量的索引,参数updates表示分散到输出张量的值,参数shape表示输出张量的形状。
函数使用
1、一维张量
>>> indices = tf.constant([[1], [3], [5], [7]])
>>> updates = tf.constant([2, 3, 4, 5])
>>> shape = tf.constant([8])
>>> tf.scatter_nd(indices, updates, shape)
<tf.Tensor: shape=(8,), dtype=int32, numpy=array([0, 2, 0, 3, 0, 4, 0, 5])>
2、二维张量
>>> indices = tf.constant([[1], [2]])
>>> updates = tf.constant([[1, 2], [3, 4]])
>>> updates
<tf.Tensor: shape=(2, 2), dtype=int32, numpy=
array([[1, 2],
[3, 4]])>
>>> shape = tf.constant([4, 2])
>>> tf.scatter_nd(indices, updates, shape)
<tf.Tensor: shape=(4, 2), dtype=int32, numpy=
array([[0, 0],
[1, 2],
[3, 4],
[0, 0]])>
3、三维张量
>>> indices = tf.constant([[0], [2]])
>>> updates = tf.constant([[[5, 5, 5, 5], [6, 6, 6, 6],
[7, 7, 7, 7], [8, 8, 8, 8]],
[[5, 5, 5, 5], [6, 6, 6, 6],
[7, 7, 7, 7], [8, 8, 8, 8]]])
>>> updates
<tf.Tensor: shape=(2, 4, 4), dtype=int32, numpy=
array([[[5, 5, 5, 5],
[6, 6, 6, 6],
[7, 7, 7, 7],
[8, 8, 8, 8]],
[[5, 5, 5, 5],
[6, 6, 6, 6],
[7, 7, 7, 7],
[8, 8, 8, 8]]])>
>>> shape = tf.constant([4, 4, 4])
>>> tf.scatter_nd(indices, updates, shape)
<tf.Tensor: shape=(4, 4, 4), dtype=int32, numpy=
array([[[5, 5, 5, 5],
[6, 6, 6, 6],
[7, 7, 7, 7],
[8, 8, 8, 8]],
[[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]],
[[5, 5, 5, 5],
[6, 6, 6, 6],
[7, 7, 7, 7],
[8, 8, 8, 8]],
[[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]]])>
边栏推荐
- 深度优先搜索(模板使用)
- Redis special data type bitmap
- MGR_ mysqlsh_ Keepalive high availability architecture deployment document
- Solution: exit status 1 and exit status 145 appear when the console uses NVM to control the node version
- MGR_mysqlsh_keepalive高可用架构部署文档
- UE4/5 无法打开文件“xxx.generated.h”(Cannot open file xxx.generated.h)的解决方法总结
- Visibility:hidden and display:none
- 【LVGL布局】柔性布局
- 数据分析思维之从整体出发分析零售行业——全方位多方面细节分析
- JSONObject按照key的A——Z顺序排序
猜你喜欢

极客星球丨 字节跳动一站式数据治理解决方案及平台架构

Special effects - when the mouse moves, there will be a custom expression trail

Esp32 ultra detailed learning record: NTP synchronization time

These 10 kinds of timed tasks have been learned, and you can float directly

安装snownlp包过程出现Requirement already satisfied:及Read timed out.问题解决方法

STM32基于 FatFs R0.14b&SD Card 的MP3音乐播放器(也算是FatFs的简单应用了吧)

【LVGL(重要)】样式属性API函数及其参数

Account and authority management

神经网络超参数调整(基于ray包)

【学习笔记】Web页面渲染的流程
随机推荐
postgresql 日期处理函数用法
广度优先搜索(模板使用)
Redis basic type - hash
Special effects - return to the top (kitten effects)
Summary browser object
Redis数据类型-列表List
Ge port: sgmii mode and SerDes mode
机器学习案例:孕妇吸烟与胎儿健康
[lvgl (4)] event and event bubble of the object
(static, dynamic, file) three versions of address book
【LVGL】【阶段总结1】
Jenkins CI CD
Redis special data type bitmap
安装snownlp包过程出现Requirement already satisfied:及Read timed out.问题解决方法
Experiment: creation, expansion, and deletion of LVM logical volumes
Special effects - click with the mouse and the fireworks will burst
【USB电压电流表】基于STM32F103C8T6 for Arduino
类加载的过程(生命周期)详情分析
不运动也能增肌???打一针冬眠黑熊的血清就行
MGR_mysqlsh_keepalive高可用架构部署文档