I did the loop. Is there a faster solution?

julia> o45
835969x26 Array{Int64,2}:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 930070 1478343 1480581 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 21474836496 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4296445417 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
...
1448463 1475452 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1379907 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

julia> o45a = (Int=>eltype(o45))[j => i for (i,j) in enumerate(unique(o45))];

julia> o45_output=zeros(o45);

julia> k,l =size(o45_output)
(835969,26)

julia> @time for j=1:l, i=1:k;
       o45_output[i,j]=get(o45a,o45[i,j],0);
       end;
elapsed time: 7.418340987 seconds (1435414160 bytes allocated, 6.41% gc time)

julia> o45_output=o45_output.-1; #makes thrue zeros


Paul
W dniu 2014-12-10 o 21:41, Paul Analyst pisze:
Thx, but not work,

julia> JJ=hcat(J,J);

julia> JJa = (Int=>eltype(JJ))[j => i for (i,j) in enumerate(unique(JJ))];

julia> JJcodes = Int64[JJa[j] for j in JJ];

julia> convert(Array{Int, 2}, Jcodes)
ERROR: `convert` has no method matching convert(::Type{Array{Int64,2}}, ::Array{Int64,1})
 in convert at base.jl:13

julia> convert(Array{Int64, 2}, Jcodes)
ERROR: `convert` has no method matching convert(::Type{Array{Int64,2}}, ::Array{Int64,1})
 in convert at base.jl:13

julia> convert(Array{Int, 2}, JJcodes)
ERROR: `convert` has no method matching convert(::Type{Array{Int64,2}}, ::Array{Int64,1})
 in convert at base.jl:13

julia> convert(Array{Int64, 2}, JJcodes)
ERROR: `convert` has no method matching convert(::Type{Array{Int64,2}}, ::Array{Int64,1})
 in convert at base.jl:13

julia> convert(Matrix{Int}, JJcodes)
ERROR: `convert` has no method matching convert(::Type{Array{Int64,2}}, ::Array{Int64,1})
 in convert at base.jl:13

julia> convert(Matrix{Int64}, JJcodes)
ERROR: `convert` has no method matching convert(::Type{Array{Int64,2}}, ::Array{Int64,1})
 in convert at base.jl:13

julia>

Paul

W dniu 2014-12-10 o 18:21, Sean Marshallsay pisze:
Vector{T} is just a typealias for Array{T, 1} so it's still an array but limited to one dimension. Your problem can be solved with

|
convert(Array{Int,2},Jcodes)
|

or equivalently

|
convert(Matrix{Int},Jcodes)
|


On Wednesday, 10 December 2014 11:09:55 UTC, paul analyst wrote:

    And how to do it if the "J" is an array rather than a vector? So
    that was also Jcodes array of the same size as J?
    julia> J
    1557211x2 Array{Int64,2}:
          930070       930070
         1475172      1475172
    ...                        .....
     21474836496  21474836496
      4296445417   4296445417

    Paul

    W dniu 2014-12-04 o 19:03, Steven G. Johnson pisze:
    It sounds like you have an array J and you want to map each
    element of J to a unique integer in 1:N for N as small as
    possible?  This will do it:

        d = (Int=>eltype(J))[j => i for (i,j) in enumerate(unique(J))]

        Jcodes = [d[j] for j in J]

    Here, d is a dictionary mapping integers in 1:N to the
    corresponding values in J, and Jcodes is the "re-coded" array.




Reply via email to