Je voudrais contrôler comment array.reshape () remplit le nouveau tableau. Par exemple
a = np.arange(9).reshape(3,3, 'columnwise') ## array([[ 0, 3, 6, 9], ## [ 1, 4, 7, 10], ## [ 2, 5, 8, 11]])
mais ce que j'aimerais pouvoir, c'est remplir le tableau par colonne avec quelque chose comme:
a = np.arange(12).reshape(3,4) ## array([[ 0, 1, 2, 3], ## [ 4, 5, 6, 7], ## [ 8, 9, 10, 11]])
3 Réponses :
Utilisez np.transpose.
[[0 3 6] [1 4 7] [2 5 8]]
Output:
import numpy as np print(np.arange(9).reshape(3,3).transpose())
Si vous transposez la matrice d'origine, vous obtiendrez l'effet souhaité.
a = np.arange(6).reshape(3,3).T
OU
import numpy as np a = np.arange(6).reshape(3,3).tranpose()
In [22]: np.arange(12).reshape(3,4, order='F')
Out[22]:
array([[ 0, 3, 6, 9],
[ 1, 4, 7, 10],
[ 2, 5, 8, 11]])