Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Julia Reverse N-dimensional arrays

Tags:

arrays

julia

In Python, Numpy arrays can be reversed using the standard [::-1] i.e.

A = np.diag(np.arange(1,3)) 
A[::, ::-1] 
A[::-1] 
A[::-1, ::-1]

Julia does not support [::-1] and the reverse method only works on 1D arrays and only 1D columns (where as rows are 2D by default).

Is there an alternative I'm missing?

like image 380
user3467349 Avatar asked Dec 10 '14 21:12

user3467349


1 Answers

Try the following, which is essentially the same as the numpy version:

julia> X = rand(3,3)
3x3 Array{Float64,2}:
 0.782622  0.996359  0.335781
 0.719058  0.188848  0.985693
 0.455355  0.910717  0.870187

julia> X[end:-1:1,end:-1:1]
3x3 Array{Float64,2}:
 0.870187  0.910717  0.455355
 0.985693  0.188848  0.719058
 0.335781  0.996359  0.782622
like image 193
IainDunning Avatar answered Sep 22 '22 20:09

IainDunning