How to replace maximum column values ​​with 1.0 using Theano?

I have a real matrix in Theano, and I want to generate a different matrix so that in each column of the new matrix I have one 1.0 and 0.0 otherwise. 1.0 should indicate the location of the maximum value in the input matrix column.

For instance. If as an input

the following matrix is ​​used,
1.0   2.0   3.0   5.0
2.1   0.0   4.0   0.0
0.0   3.0   1.0   4.0

The following matrix should be generated as output:

0.0   0.0   0.0   1.0
1.0   0.0   1.0   0.0
0.0   1.0   0.0   0.0

The solution I am using so far is as follows:

tmp = T.max(inp, axis = 0).dimshuffle('x',0)
out = T.switch(T.eq(tmp, inp), 1.0, 0.0)

, , . , , . , - "" ?

+4
2

:

out = T.eye(3)[T.argmax(inp, axis=0)].T  # replace 3 with number of rows

:

0.0   0.0   0.0   1.0
1.0   0.0   1.0   0.0
0.0   1.0   0.0   0.0
+1

argmax max dimshuffle. Argmax , .

tmp = T.argmax(inp, axis = 0)

tmp, 1.0 ( / , )

+1

Source: https://habr.com/ru/post/1678430/


All Articles