Hi,
I am searching for a command which is similar to python "numpy.where()". 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.
ex: 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?
I tried to write array search for a tensor. However I end up with error when calling "if K.equal():" line as
TypeError: Using a tf.Tensor as a Python bool is not allowed. Use if t is not None: instead of if t: to test if a tensor is defined, and use TensorFlow ops such as tf.cond to execute subgraphs conditioned on the value of a tensor.
y_true = [0 1 1 0 0 2 3 ]
def loss(y_true, y_pred):
b=K.equal(y_true,0)
b=K.cast(b,dtype='float32')
for i in range(0,7):
if K.equal(b[i],1):
........
I am wondering why there is not any inbuilt function for this purpose. In keras backend simply If I know the indices I can use K.gather() to select those values. However, when comes to this problem I couldn't able to think of any method to find indices by using existing keras backend commands. So the only option is writing a searching algorithm using "for loop" and "if command". Moreover, when writing if command apparently it does not support keras boolean tensors.
--
You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users+unsubscribe@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/9068a1b3-b74f-4e2f-a732-98be6e41d108%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
What is your ultimate goal? Which loss function are you trying to implement? I fear this may be a instance of the XY problem, and there may be easier ways to accomplish it.
https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem
On 24 April 2017 at 00:51, <sarith.k...@gmail.com> wrote:
Hi,
I am searching for a command which is similar to python "numpy.where()". 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.
ex: 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?
I tried to write array search for a tensor. However I end up with error when calling "if K.equal():" line as
TypeError: Using atf.Tensoras a Pythonboolis not allowed. Useif t is not None:instead ofif t:to test if a tensor is defined, and use TensorFlow ops such as tf.cond to execute subgraphs conditioned on the value of a tensor.
y_true = [0 1 1 0 0 2 3 ]
def loss(y_true, y_pred):
b=K.equal(y_true,0)
b=K.cast(b,dtype='float32')
for i in range(0,7):
if K.equal(b[i],1):
........
I am wondering why there is not any inbuilt function for this purpose. In keras backend simply If I know the indices I can use K.gather() to select those values. However, when comes to this problem I couldn't able to think of any method to find indices by using existing keras backend commands. So the only option is writing a searching algorithm using "for loop" and "if command". Moreover, when writing if command apparently it does not support keras boolean tensors.
--
You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users...@googlegroups.com.