如何在数组中的每个x值中找到最小值?

时间:2017-03-11 15:33:00

标签: python numpy minimum

path = ("C:/Users/Calum/AppData/Local/Programs/Python/Python35-32/Python Programs/PV Data/Monthly Data/brunel-11-2016.csv")
with open (path) as f:
    readCSV = csv.reader((islice(f, 0, 8352)), delimiter = ';')
    irrad_bru1 = []

    for row in readCSV:
         irrad1 = row[1]

         irrad_bru1.append(irrad1)

irrad_bru1 = ['0' if float(x)<0 else x for x in irrad_bru1]
bru_arr1 = np.asarray(irrad_bru1).astype(np.float)

rr_bru1 = -np.diff(bru_arr1)

我想在每200个条目中找到数组rr_bru1中的最小值我该怎么做?

2 个答案:

答案 0 :(得分:0)

您可以使用np.minimum.reduceat

np.minimum.reduceat(a, np.arange(0, len(a), 200))

答案 1 :(得分:0)

使用切片的一种方法:

Python 3

n = 200
[min(mylist[i:i + n]) for i in range(0, len(mylist), n)]

Python 2

n = 200
[min(mylist[i:i + n]) for i in xrange(0, len(mylist), n)]