thank you On Wed, Sep 7, 2016 at 12:03 PM, Mosè Giordano <mose.giord...@gmail.com> wrote:
> Hi Ahmed, > > > Hello, >> l have a matrix as follow : >> k=rand(1:100,3,3) >> 3x3 Array{Int64,2}: >> 97 26 77 >> 58 64 86 >> 87 85 99 >> >> >> l want to shuffle randomly the order by lines for instance line 1 becomes >> 3. l have a matrix of 10000 by 700 . >> > > The following function is based on the definition of shuffle! in Julia > 0.4 (it's different in Julia 0.5) > > function shufflerows!{T<:Real}(a::AbstractArray{T}) > for i = size(a, 1):-1:2 > j = rand(1:i) > a[i,:], a[j,:] = a[j,:], a[i,:] > end > return a > end > > Here is it in action: > > julia> a = rand(1:100, 5, 3) > 5x3 Array{Int64,2}: > 18 90 34 > 9 24 61 > 49 73 84 > 70 85 20 > 66 59 37 > > julia> shufflerows!(a) > 5x3 Array{Int64,2}: > 9 24 61 > 18 90 34 > 70 85 20 > 49 73 84 > 66 59 37 > > Note that the matrix is changed in-place. > > Cheers, > Mosè >