1. As in Ethan's response (modulo a trivial bug): Matrix[x[k,:] for k=1:size(x,1)]
Depending on how well typed the result needs to be, the leading 'Matrix' can be dropped or be made more specific. 2. I wouldn't say so but opinions vary depending on mathematical and programming language biases. There are several issues and mailing list threads on this subject. You can start with https://github.com/JuliaLang/julia/issues/5949 and follow links or search further if that doesn't satiate your appetite. Den fredagen den 8:e augusti 2014 kl. 01:31:23 UTC+2 skrev K leo: > > 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? > > > > > >