numpy.swapaxes

Cette fonction intervertit les deux axes d'un tableau. Pour les versions NumPy après 1.10, une vue du tableau permuté est renvoyée. La fonction prend les paramètres suivants.

numpy.swapaxes(arr, axis1, axis2)

Où,

Sr.No. Paramètre et description
1

arr

Tableau d'entrée dont les axes doivent être permutés

2

axis1

Un int correspondant au premier axe

3

axis2

Un int correspondant au deuxième axe

Exemple

# It creates a 3 dimensional ndarray 
import numpy as np 
a = np.arange(8).reshape(2,2,2) 

print 'The original array:' 
print a 
print '\n'  
# now swap numbers between axis 0 (along depth) and axis 2 (along width) 

print 'The array after applying the swapaxes function:' 
print np.swapaxes(a, 2, 0)

Sa sortie serait la suivante -

The original array:
[[[0 1]
 [2 3]]

 [[4 5]
  [6 7]]]

The array after applying the swapaxes function:
[[[0 4]
 [2 6]]
 
 [[1 5]
  [3 7]]]