7

I have an array that I would like to switch the axes order of. It is similar to a transpose except I would like to perform it on arrays with dimensions greater than 2. In Python I would use np.transpose and in Matlab, permute, but I can't seem to find this in Julia. For instance,

a = ones(2, 3, 4)
size(a)
(2,3,4)

From this I would like to get an array of shape (3, 4, 2) by rearranging the axes (dimensions) to (2, 3, 1). I am looking for a function called new_func.

b = new_func(a, (2, 3, 1))
size(b)
(3,4,2)
Kipton Barros
  • 21,002
  • 4
  • 67
  • 80
jtorca
  • 1,531
  • 2
  • 17
  • 31

1 Answers1

10

According to Stefan Karpinski, the answer is Base.permutedims (docs).

Example:

a = ones(2, 3, 4)
size(a) # => (2,3,4)

b = permutedims(a, [2, 3, 1])
size(b) # => (3,4,2)
Kipton Barros
  • 21,002
  • 4
  • 67
  • 80