Thanks to both for the responses.

Related questions: how does one turn a 2-dimensional array into a 1-dimensional array of row arrays? Also, the default behavior of julia is that a row of a 2-dimensional array is also a 2-dimensional array. Would anyone comment why this is the case? Should it better be a 1-dimensional array?

On 2014年08月07日 19:59, Ethan Anderes wrote:

Here is another one…slightly different:

|in(x[1,:], Matrix[x[k,:] for  k=1:size(x,2)] )
|

To be honest, the custom for loop is probably your best bet in terms of performance:

|function isrow(row, x::Matrix)
    for k=1:size(x,1)
       if row == x[k,:]
          return true
       end
    end
    false
end
|

On Thursday, August 7, 2014 1:36:08 AM UTC-7, Gunnar Farnebäck wrote:

    Is this easy enough?

    julia> x = reshape(1:16, 4, 4)
    4x4 Array{Int64,2}:
     1  5   9  13
     2  6  10  14
     3  7  11  15
     4  8  12  16

    julia> a = x[1,:]
    1x4 Array{Int64,2}:
     1  5  9  13

    julia> [a == x[k,:] for k = 1:size(x,1)]
    4-element Array{Any,1}:
      true
     false
     false
     false

    julia> any([a == x[k,:] for k = 1:size(x,1)])
    true

    julia> find([a == x[k,:] for k = 1:size(x,1)])
    1-element Array{Int64,1}:
     1


    Den torsdagen den 7:e augusti 2014 kl. 06:09:23 UTC+2 skrev K leo:

        julia> x
        4x4 Array{Int64,2}:
          1  5   9  13
          2  6  10  14
          3  7  11  15
          4  8  12  16

        julia> in(x[1,:], x)
        false

        julia> x[1,:]
        1x4 Array{Int64,2}:
          1  5  9  13

        How can I check if x[1,:] is in x easily?  And with the row
        index in x?

​

Reply via email to