给定一个形状为 A 的矩阵,(1000000,6)
我想出了如何为每一行获取最小最右边的值并在这个函数中实现它:
def calculate_row_minima_indices(h): # h is the given matrix.
"""Returns the indices of the rightmost minimum per row for matrix h."""
flipped = numpy.fliplr(h) # flip the matrix to get the rightmost minimum.
flipped_indices = numpy.argmin(flipped, axis=1)
indices = numpy.array([2]*dim) - flipped_indices
return indices
indices = calculate_row_minima_indices(h)
for col, row in enumerate(indices):
print col, row, h[col][row] # col_index, row_index and value of minimum which should be removed.
每行都有一个最小值。所以我需要知道的是删除具有最小值的条目并将带有shape的 Matrix缩小为带有shape(1000000,6)
的矩阵。(1000000,5)
我会生成一个具有较低维度的新矩阵,并使用 for 循环使用我希望它携带的值填充它,但我害怕运行时。那么是否有一些内置的方法或技巧可以通过每行的最小值来缩小矩阵?
也许这个信息是有用的:这些值都大于或等于 0.0。