如何找到一个巨大的csv文件的10个最大值?

时间:2019-01-15 17:21:45

标签: python algorithm image-processing minmax

我正在尝试查找Harris算法给出的.csv文件的10个最大值。你能帮我吗?我找到一种方法来找到最大值,但不能先找到10。

import cv2
import numpy as np
from numpy import genfromtxt

filename = 'boy.jpg'

img = cv2.imread(filename)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

gray = np.float32(gray)
dst = cv2.cornerHarris(gray, 2, 3, 0.04)

# result is dilated for making the corners, not important
dst = cv2.dilate(dst, None)

# Threshold for an optional value, it may vary depending on the image.
img[dst > 0.01 * dst.max()] = [0, 0, 255]

cv2.imshow('dst', img)

np.savetxt("data2.csv", dst, delimiter=",")

if cv2.waitKey(0) & 0xff == 27:
    cv2.destroyAllWindows()

import numpy
data1 = numpy.genfromtxt("data2.csv",dtype='float',delimiter =',', skip_header=0, skip_footer=0,usecols=11,usemask=True)
#print data1
print(data1.min())
print(data1.max())

1 个答案:

答案 0 :(得分:1)

将数据框按列排序,然后打印出前10个。

df.sort_values('some_column', ascending=False)[:10]