在 TensorFlow 中展平包含向量的 2D 张量的最佳方法? [英] Best way to flatten a 2D tensor containing a vector in TensorFlow?

查看:41
本文介绍了在 TensorFlow 中展平包含向量的 2D 张量的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将实际上是水平或垂直向量的二维张量展平为一维张量的最有效方法是什么?

What is the most efficient way to flatten a 2D tensor which is actually a horizontal or vertical vector into a 1D tensor?

在性能方面是否存在差异:

Is there a difference in terms of performance between:

tf.reshape(w, [-1])

tf.squeeze(w)

?

推荐答案

Both tf.reshape(w, [-1])tf.squeeze(w) 是便宜的",因为它们只对给定张量的元数据(即形状)进行操作,而不修改数据本身.两个 tf.reshape() 中略有 内部逻辑更简单,但两者的性能应该没有区别.

Both tf.reshape(w, [-1]) and tf.squeeze(w) are "cheap" in that they operate only on the metadata (i.e. the shape) of the given tensor, and don't modify the data itself. Of the two tf.reshape() has slightly simpler logic internally, but the performance of the two should be indistinguishable.

这篇关于在 TensorFlow 中展平包含向量的 2D 张量的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆