python - Tensorflow:矩阵矩阵的对角线/ 4D张量的对角线
问题描述
x
给定一个shape的 4D 张量(batch_size, batch_size, seq_len, feature_dim)
,我希望能够沿对角线条目检索矩阵,即我需要一种方法来获取所有x[diag_entry, diag_entry, :, :]
切片以获取range(batch_size)
产生 shape 的张量的值(batch_size, seq_len, feature_dim)
。但是,由于我在 Keras 工作,因此我无法明确循环,range(batch_size)
因为可能会有所不同。batch_size
Tensorflow 是否具有支持此类操作的功能?
解决方案
推荐阅读
- javascript - 如何关闭当前浏览器窗口?
- android - 如何通过 Espresso 检查拨号器上的电话号码 - 通过 autoLink 触发的拨号器
- python - 如何将 2 个字符串 a、b 连接到 C,然后仅使用 C 检索 a、b 的值。对 a 和 b 的输入没有限制
- intellij-idea - IntelliJ IDEA JUnit5 标签运行配置错误模块未指定
- sql - MS Access VBA/SQL - 从 3 个表中选择不同的匹配记录并更新单个列
- javascript - Replace a line in txt file using JavaScript
- r - Lapply 和 for 循环在动态创建图形时产生不同的结果
- r - R converting FB json friend list to data frame
- java - 如何在 TEXTVIEW 中捕获 JSON 响应?
- google-sheets - Changing formula (with consecutive relative references) into an array formula so it will work with google forms input