Nawra C
Nawra C

Reputation: 166

Best way to transpose nested arrays within array than a for loop

I have an numpy array of shape (43200, 28, 28), which contains 43200 images of size 28x28. I'd like to transpose each of these images but can't find a better way to do it than with a loop such as

for i in range(arr.shape[0]):
  arr[i] = arr[i].T

Is there a more efficient way ?

Upvotes: 0

Views: 113

Answers (1)

Cory Kramer
Cory Kramer

Reputation: 117876

You can preserve the 0 axis, but transpose the latter two

arr.transpose(0, 2, 1)

Upvotes: 2

Related Questions