本文介绍了Keras:如何从张量中找到与numpy.where()类似的特定值的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在搜索类似于python "numpy.where()"
命令的Keras命令.基本上,我的想法是从张量中提取索引.在python中,我可以简单地执行f_j=(np.where(X==j))
,这会给我特定的indices(f_j)
值j
.
I am searching for a Keras command which is similar to python "numpy.where()"
command. Basically, my idea is to extract the indices from a tensor. In python I can do simply f_j=(np.where(X==j))
which gives me specific indices(f_j)
for the value j
.
例如:
X= [0 1 1 0 0 2 3 ]
f_j=(np.where(X==1))
f_j= [1 2]
我可以使用任何类似的功能吗?
Is there is any similar function which I can use for this purpose ?
我试图在张量中编写数组搜索.但是,当调用"if K.equal():"
行为
I tried to write array search inside a tensor. However, I end up with error when calling "if K.equal():"
line as
def loss(y_true, y_pred:
b=K.equal(y_true,0)
b=K.cast(b,dtype='float32')
for i in range(0,5):
if K.equal(b[i],1):
........
y_true = [0 1 1 0 0 2 3 ]
推荐答案
您应尝试以下操作:
from keras import backend as K
value = 5
wh = K.tf.where(K.tf.equal(x,value))
当您的后端是张量流时.
when your backend is tensorflow.
希望有帮助
这篇关于Keras:如何从张量中找到与numpy.where()类似的特定值的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!