首页 > 解决方案 > 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_sizeTensorflow 是否具有支持此类操作的功能?

标签: pythontensorflowkeras

解决方案


推荐阅读