【发布时间】:2012-03-11 05:09:14
【问题描述】:
给定一个形状为(1000000,6) 的矩阵A,我已经想出了如何为每一行获取最小最右边的值并在这个函数中实现它:
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.
每一行都有一个最小值。所以我需要知道的是删除具有最小值的条目并将形状为(1000000,6)的矩阵收缩为带有的矩阵形状(1000000,5)。
我会生成一个具有较低维度的新矩阵,并使用 for 循环使用我希望它携带的值填充它,但我担心运行时。 那么有没有一些内置的方法或技巧可以通过每行的最小值来缩小矩阵?
也许这个信息是有用的:这些值都大于或等于 0.0。
【问题讨论】:
标签: python numpy scipy minimum