Problèmes de tri et d'indexation

1  '' ' 
2  1. Vérifiez la position du plus grand index sur la colonne
 3      data.argmax (axe = 0)
 4  2. Sortez l'élément à la position d'index
 5      data [index, range (data.shape [1])]
 6      Use range Afficher quelques éléments
 7  3. Développer les objets numpy
 8      a = np.array ([4,5,6,2])
 9      np.tile (a, (2,3))
 10  4. Trier le tableau par ligne , De petit à grand
 11      a = np.array ([[4,3,5], [1,7,6]])
 12      np.sort (a, axis = 1)
 13  5. Triez les éléments du tableau et retournez Indice index
 14      a = np.array ([4,3,1,2])
 15      j = np.argsort (a)
 16      a [j]
 17  '' 
'18  importnumpy as np
 19 data = np.array ([
 20      [4,5,6,8 ],
 21      [7,4,2,8 ],
 22      [9,5,4,2 ]
 23  ])
 24 data.argmax (axe = 0)
 25  # array ([2, 0, 0, 0], dtype = int64) 
26 data.argmax (axis = 1 )
 27  # array ([3, 3, 0], dtype = int64) 
28 index = data.argmax (axe = 0)
 29  # array ([9, 5, 6, 8]) 
30 a = np.array ([4,5,6,2 ])
 31 np.tile (a, (2, 3 ))
 32  '' '
33  tableau ([[4, 5, 6, 2, 4, 5, 6, 2, 4, 5, 6, 2],
 34         [4, 5, 6, 2, 4, 5, 6, 2, 4, 5, 6, 2]])
 35  '' ' 
36 a = np.array ([[4,3,5], [1,7,6 ]])
 37  ''' 
38  array ([[4, 3, 5],
 39         [1, 7, 6]])
 40  '' ' 
41 np.sort (a, axe = 1 )
 42  ''' 
43  array ([[3, 4, 5],
 44         [1, 6, 7]])
 45  '' ' 
46 np.sort (a, axe = 0)
 47  ''' 
48  array ([[1, 3, 5],
 49         [4, 7,
6]]) 50  '' 
'51a = np.array ([4,3,1,2 ])
 52 j = np.argsort (a)
 53  # array ([1, 2, 3, 4])

2020-04-10

Je suppose que tu aimes

Origine www.cnblogs.com/hany-postq473111315/p/12672695.html
conseillé
Classement