当前位置:网站首页>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]]])>
边栏推荐
- [lvgl] [stage summary 1]
- Special effects - mouse click, custom DOM follow move
- Machine learning case: smoking in pregnant women and fetal health
- It's not too much to fight a landlord in idea!
- 【学习笔记】从汇编看 a+++a与 a+a++的区别
- [esp8266 spot welder] Based on esp8266 for Arduino
- [jquery custom plug-in] 1 custom cache plug-in -jquerycache
- Browser local storage
- [lvgl (4)] event and event bubble of the object
- nodejs开启多进程并实现进程间通信
猜你喜欢

Redis分布式缓存学习笔记

【学习笔记】网页出现白屏可能的原因与优化方法

【LVGL布局】网格布局

Mac can't connect to local MySQL server through socket '/tmp/mysql Sock '(2) problem

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

【LVGL(6)】显示中文设置,制作中文字库

Redis.conf details
![[lvgl (4)] event and event bubble of the object](/img/1e/9fe3d34f5f8d8c7298a106dca8d949.png)
[lvgl (4)] event and event bubble of the object

UE4/5 无法打开文件“xxx.generated.h”(Cannot open file xxx.generated.h)的解决方法总结

Account and authority management
随机推荐
Solution: exit status 1 and exit status 145 appear when the console uses NVM to control the node version
Special effects - cobweb background effects
ESP32超详细学习记录:NTP同步时间
js和ts学习总结
创建WPF项目
【LVGL(1)】LVGL的简单介绍
Jenkins CI CD
Kubernetes rapid installation
Special effects - click the mouse, and a random color of love will appear
STM32 MP3 music player based on FatFs r0.14b & SD card (also a simple application of FatFs)
Summary browser object
【LVGL布局】网格布局
Talk about strong cache and negotiation cache
【LVGL】【阶段总结1】
随机森林、LGBM基于贝叶斯优化调参
Kubernetes' deployment, service concept, dynamic capacity expansion
【学习笔记】Web页面渲染的流程
Esp32 ultra detailed learning record: NTP synchronization time
【ESP8266点焊机】基于 ESP8266 for Arduino
STM32基于 FatFs R0.14b&SD Card 的MP3音乐播放器(也算是FatFs的简单应用了吧)