What do you want to achieve - shuffling along a dimension (i.e. shuffling 
rows or columns), or just shuffling all the numbers?

For the latter, it can be achieved pretty easily by reshaping to a vector 
and back. This has the added benefit that it generalizes well to arbitrary 
dimensions:

julia> A = reshape(1:40, 4,5,2)
4x5x2 Array{Int64,3}:
[:, :, 1] =
 1  5   9  13  17
 2  6  10  14  18
 3  7  11  15  19
 4  8  12  16  20

[:, :, 2] =
 21  25  29  33  37
 22  26  30  34  38
 23  27  31  35  39
 24  28  32  36  40

julia> reshape(shuffle(vec(A)), size(A)...)
4x5x2 Array{Int64,3}:
[:, :, 1] =
 32  38   8  21   6
 29  25  31  13  20
 34  10   4  33  39
 18   5  27   7  15

[:, :, 2] =
 40  22  30  19  16
 11  23  14  36  26
 17   3  24   1  37
 35  28   9   2  12

// T

On Thursday, March 24, 2016 at 2:09:36 PM UTC+1, Arundhyoti Sarkar wrote:


>
> Is there a way to shuffle matrix in julia like we do in matlab?
> I know shuffle(v) shuffles the vector v of type Array{Any,1}. But doesnot 
> work with matrices. 
>
​

Reply via email to