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)
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With