python - 如何从张量中提取子矩阵?

标签 python machine-learning tensorflow

我想提取张量的前两列。

例如, 考虑这个张量

[[0, 1, -1, -2, -3],

 [1, 0, -8, -2, -3]]

输出应该是

[[0,1],
[1,0]]

我使用了 tf.unstack() 但无法完全成功。

最佳答案

使用tensorflow的python切片运算符,比 Kris Roofe 的解决方案更具可读性:

tensor[:,0:2]

如果您熟悉Python的标准切片表示法,那么您已经知道如何使用tensorflow。

关于python - 如何从张量中提取子矩阵?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45082653/

相关文章:

python - Python 中的 Open() 和 read() 方法未添加到列表中

python - 为什么 Pytorch (CUDA) 在 GPU 上运行缓慢

machine-learning - 线性回归::归一化 (Vs) 标准化

tensorflow - 如何使用 tensorflow.Estimator 进行强化学习

tensorflow.python.framework.errors_impl.ResourceExhaustedError

python - Bokeh - 从 BoxZoomTool/ResetTool 触发 on_change 回调

python - 如何在 Python 中验证字典的结构(或模式)?

python - 如何将二维列表写入txt文件?

python - XGBoost plot_importance 不显示特征名称

tensorflow - 此浏览器不支持 WebGL。在 createWebGLRenderingContextFromCanvas?