ฉันต้องการวาดแผนภูมิในแอปพลิเคชันหลามของฉัน แต่อาร์เรย์ numpy ของแหล่งที่มามีขนาดใหญ่เกินไปสำหรับการทำเช่นนี้ (ประมาณ 1'000'000+) ฉันต้องการหาค่าเฉลี่ยขององค์ประกอบข้างเคียง แนวคิดแรกคือการทำในรูปแบบ C++:
step = 19000 # every 19 seconds (for example) make new point with neam value
dt = <ordered array with time stamps>
value = <some random data that we want to draw>
index = dt - dt % step
cur = 0
res = []
while cur < len(index):
next = cur
while next < len(index) and index[next] == index[cur]:
next += 1
res.append(np.mean(value[cur:next]))
cur = next
แต่วิธีนี้ทำงานช้ามาก ฉันพยายามทำ สิ่งนี้:
step = 19000 # every 19 seconds (for example) make new point with neam value
dt = <ordered array with time stamps>
value = <some random data that we want to draw>
index = dt - dt % step
data = np.arange(index[0], index[-1] + 1, step)
res = [value[index == i].mean() for i in data]
pass
วิธีแก้ปัญหานี้ช้ากว่าวิธีแรก ทางออกที่ดีที่สุดสำหรับปัญหานี้คืออะไร?