from array
[3,1,7,2; 4,3,2,7; 3,4,1,2] i extract subarray corresponding rows having last entree equal 2.
i matlab user trying start using julia. looked hint in docs failed find working answer.
thank in advance,
stephane
does work you?
julia> x = [3 1 7 2 4 3 2 7 3 4 1 2] 3x4 array{int64,2}: 3 1 7 2 4 3 2 7 3 4 1 2 julia> x[x[:, end] .== 2, :] 2x4 array{int64,2}: 3 1 7 2 3 4 1 2 let's break down.
x[:, end] last column.
x[:, end] .== 2 gives vector{bool} (1d array of true , false), have true if row ends in 2 , false otherwise.
then putting have x[x[:, end] .== 2, :], takes vector of true , false specify rows , ,: says take columns in each of rows.
Comments
Post a Comment