- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
按照 tf.case
文档中的这个例子:
def f1(): return tf.constant(17)
def f2(): return tf.constant(23)
def f3(): return tf.constant(-1)
r = tf.case({tf.less(x, y): f1, tf.greater(x, z): f2},
default=f3, exclusive=True)
我想做同样的事情,但允许使用 feed_dict 作为输入,如下图所示:
x = tf.placeholder(tf.float32, shape=[None])
y = tf.placeholder(tf.float32, shape=[None])
z = tf.placeholder(tf.float32, shape=[None])
def f1(): return tf.constant(17)
def f2(): return tf.constant(23)
def f3(): return tf.constant(-1)
r = tf.case({tf.less(x, y): f1, tf.greater(x, z): f2},
default=f3, exclusive=True)
print(sess.run(r, feed_dict={x: [0, 1, 2, 3], y: [1, 1, 1, 1], z: [2, 2, 2, 2]}))
# result should be [17, -1, -1, 23]
所以,基本上我想提供三个长度相等的 int
数组,并接收一个包含 17、23 或 -1 的 int
值数组。不幸的是,上面的代码给出了错误:
ValueError: Shape must be rank 0 but is rank 1 for 'case/cond/Switch' (op: 'Switch') with input shapes: [?], [?].
我知道,tf.case
需要 bool 标量张量输入值,但有什么方法可以实现我想要的吗?我也尝试了 tf.cond
但没有成功。
最佳答案
使用tf.where
为此,例如像这样( broadcasting support for tf.where
seems to be on its way ,但据我所知还没有,所以你必须确保所有参数都具有相同的大小和一个向量,或者 tf.fill
, tf.tile
。 ..).
import tensorflow as tf
with tf.Graph().as_default(), tf.Session() as sess:
x = tf.placeholder(tf.float32, shape=[None])
y = tf.placeholder(tf.float32, shape=[None])
z = tf.placeholder(tf.float32, shape=[None])
ones = tf.ones_like(x)
r = tf.where(x < y, 17 * ones, tf.where(x > z, 23 * ones, -ones))
print(sess.run(r, feed_dict={x: [0, 1, 2, 3], y: [1, 1, 1, 1], z: [2, 2, 2, 2]}))
# [17. -1. -1. 23.]
关于python - 将数组(等级为 1 的形状)馈送到 TensorFlow tf.case,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56635027/
这可能是一个简单的“不可能”的答案,但我想确定一下。我目前正在使用 LibreOffice,但如果可以在 Excel 中使用,我可以切换。 我有一个包含几个表格的电子表格,每个表格都有不同数据的相同测
我有一个应用程序,并且在主gradle文件中编写: task myTask { def command = "wsimport -s src" + File.separator + "main
我正在尝试使用点云库从点云中分割一个平面,并且我有一些有关平面模型的先验信息(即法线应该类似于z轴,高度(d)应该大约为0) 。 有没有办法强制我的RANSAC算法选择与我先前模型相似的系数?我认为可
我正在为一个发票项目开发一个基于 excel 的设备数据库。每个独特的项目都有自己的工作簿,但我正在尝试构建一个模板工作簿来限制每个项目的发票中有多少手动工作。每件设备都有一个型号、序列号和允许的地址
嗨, friend 们,我正在开发位置查找应用程序,每次我进入 map 页面时,我都会收到如下警告: "Received memory warning. Level=1" 应用程序崩溃后,我不知道该怎
我在状态中设置了 score、topicTotal 和 level,我正在打印它们中的每一个。 topicTotal 是所有分数相加的最终分数,level 基于它们的 topicTotal。 scor
这个问题在这里已经有了答案: How can I change an element's class with JavaScript? (33 个答案) 关闭 4 年前。
是否可以根据条件扩展 Ember 类?像这样的事情: A.reopen({ if (condition) { init: function() { this.super();
我有以下 DataFrame,其中包含两组动物以及它们每天吃多少食物, df = pd.DataFrame({'animals': ['cat', 'cat', 'dog', 'dog', 'rat'
下面的代码尝试使用 mpi 查找数组的最大数量.但是我不断收到以下错误: Rank 2 in job 47 caused collective abort of all ranks. Exit sta
我在 Tensorflow 文档主页上找到以下关于在等级>2 时使用 matmul 操作的内容: https://www.tensorflow.org/api_docs/python/math_ops
我试图弄清楚如何将Android Library项目分发给某些Beta用户,但是在分发并将其用于示例项目时遇到了一些问题。我正在尝试分发AAR文件。 我的示例项目中的所有内容都可以正常编译,但出现错误
我收到了以下 gradle 构建文件 (gae.gradle),其中包含来自 SpringSource 的示例项目,但是当我尝试使用 gradle 运行它时: gradle gae 它生成错误: FA
我想知道基于我的数据库结构的排名: 我有一个模型 Post 属于一个名为 Edition 的模型(也是 one Edition 有很多 Post). 一个Post有很多Like。 我想根据特定 Edi
我试图在登录页面中向正文添加一个类“bodyLogin”,并在所有其他页面中将其删除。angular的方式应该怎么做? 最佳答案 正如 Jeremy 所建议的那样,我使用了 ng 类,但在自动设置 $
我从 PHPClasses 网站获得了以下 ELO 类。 $S2) { $E = 120 - round(1 / (1 + pow(10, (($R2 - $R1)
我是 Matlab/Octave 用户。 Numpy 文档说 array 比 matrix 更可取。有没有一种方便的方法来处理 rank-1 数组,而不需要不断地 reshape 它? 例子: dat
比如说,我使用 MPI 运行一个并行程序。执行命令 mpirun -n 8 -npernode 2 总共启动8个进程。即每个节点有 2 个进程,总共有 4 个节点。 (OpenMPI 1.5)。其中
我需要按分区(或组)对行进行排名,即如果我的源表是: NAME PRICE ---- ----- AAA 1.59 AAA 2.00 AAA 0.75 BBB 3.48 BBB 2.19 B
我必须从文件中填充 CMake 变量缓存。 我在defaultConfig.externalNativeBuild.cmake.arguments(-C options.cmake)中添加了一个参数。
我是一名优秀的程序员,十分优秀!