[PYTHON] Numpy creates a matrix with only the columns whose total values of the columns of the matrix are the top X

python


import numpy as np
X = 5  #Top 5 total values
a = np.random.randint(0, 100, 100).reshape(10, 10)
#Create a vector that sums the column elements of a matrix
sum_row_vec = np.sum(a, axis=0)
#Get the index with the highest X in the column sum
top_indecies = sum_row_vec.argsort()[-X:][::-1]
#Sort by index
np.sort(top_indecies)
top_row_a = a[:, top_indecies]

Recommended Posts

Numpy creates a matrix with only the columns whose total values of the columns of the matrix are the top X
[Python] Precautions when finding the maximum and minimum values in a numpy array with a small number of elements
A collection of Numpy, Pandas Tips that are often used in the field
[Numpy, scipy] How to calculate the square root of a semi-fixed definite matrix
Find a position above the threshold with NumPy
Calculate the total number of combinations with python
Numpy leave? !! Partial differential of matrix with Sympy
Python x Bradley-Visualize the transition of the strength values of both the Interleague League with Terry's Model
[Python & SQLite] I analyzed the expected value of a race with horses with a win of 1x ②