如何从张量流中的常量创建向量 [英] How to create a vector from a constant in tensorflow

查看:17
本文介绍了如何从张量流中的常量创建向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从张量流常数/变量等创建张量流向量?例如,我有一个常量 x,我想创建一个向量,它是 [x].

How is it that you would create a tensorflow vector from a tensorflow constant/variable etc? For example I have a constant x and I want to create a vector which is [x].

我已经尝试了下面的代码,但它不起作用.任何帮助将不胜感激.

I have tried the code below and it doesn't work. Any help would be appreciated.

x = tf.placeholder_with_default(1.0,[], name="x")
nextdd = tf.constant([x], shape=[1], dtype=tf.float32)

推荐答案

从你的描述看来,你想使用 tf.expand_dims:

From you description, it looks like you want to use tf.expand_dims:

# 't' is a tensor of shape [2]
tf.shape(tf.expand_dims(t, 0))  # [1, 2]
tf.shape(tf.expand_dims(t, 1))  # [2, 1]
tf.shape(tf.expand_dims(t, -1))  # [2, 1]

这篇关于如何从张量流中的常量创建向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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