How about this:
function change_min_max!{T}(m::Array{T,2})
for row = 1:size(m, 1)
m[row, findmax(m[row, :])[2]] = one(T)
m[row, findmin(m[row, :])[2]] = zero(T)
end
end
Two caveats. First, I'm guessing this won't be that fast, because it's
traversing through rows instead of columns, but maybe you're not worried
about speed.
Second, this doesn't handle ties (you didn't say how you wanted to handle
them)
El martes, 6 de octubre de 2015, 15:32:15 (UTC-5), Steven G. Johnson
escribió:
>
> On Tuesday, October 6, 2015 at 4:27:40 PM UTC-4, Rosangela Oliveira wrote:
>>
>> The idea is to read each matrix nxm and to replace the max value=1 and
>> min value=0 in case when max and min its the same value, the first receive
>> 1 and the second recive 0.
>>
>
> Just write loops. It will be way less convoluted, and way faster, than
> any construction using find etc.
>
> With Matlab and Python, every programming problem is an exercise in mining
> the standard library for (you hope) just the right functions for your
> problem, because any code that you write yourself will be slow. Julia
> doesn't have that problem, and often the most straightforward code is also
> the best code.
>