万千封印
您应该查看 numpy() ,特别是np.min()。然后代码可以是:# Convert 'x' to np array-x_np = np.asarray(x)# Sanity check-x_np'''array([[ 8, 7, 10, 8, 8], [ 6, 6, 3, 6, 6], [ 9, 4, 2, 8, 3], [ 2, 4, 5, 3, 4]])'''# Minimum elements by squashing the columns-np.min(x_np, axis = 1)# array([7, 3, 2, 2])# Minimum elements by squashing the rows-np.min(x_np, axis = 0)# array([2, 4, 2, 3, 3])