Dear all,
I have a matrix and i want to set element less than threshold to 0 in each
column.
For example, threshold is 0 and the matrix is:
[[-3,-2,-1],
[0,1,2],
[3,4,5]]
Desired output is
[[0,0,0],
[0,1,2],
[3,4,5]]
I use theano.scan to implement it, but the output becomes
[[[ 0. -2. -1.]
[ 0. 1. 2.]
[ 3. 4. 5.]]
[[-3. 0. -1.]
[ 0. 1. 2.]
[ 3. 4. 5.]]
[[-3. -2. 0.]
[ 0. 1. 2.]
[ 3. 4. 5.]]]
How to solve this problem? My code is
def set_value_at_position(col_index, threshold, matrix):
column = matrix[:,col_index]
return T.set_subtensor(column, T.where(column<threshold, 0, column))
if __name__ == '__main__':
values = T.vector("values")
model = T.matrix('output_model')
location = T.arange(model.shape[1])
tmp, updates = theano.scan(fn=set_value_at_position,
outputs_info=None,
sequences=[location, values],
non_sequences=model
)
#result = T.sum(tmp, axis=0)
assign_values_at_pos = theano.function(
inputs=[values, model],
outputs=tmp
)
test_values = np.asarray([0, 0,0], dtype=np.float32)
test_out_model = np.asarray([[-3,-2,-1],
[0,1,2],
[3,4,5]],
dtype=np.float32)
print(assign_values_at_pos( test_values, test_out_model))
--
---
You received this message because you are subscribed to the Google Groups
"theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.