久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

索引對之間子數(shù)組中值的 Numpy 總和

Numpy sum of values in subarrays between pairs of indices(索引對之間子數(shù)組中值的 Numpy 總和)
本文介紹了索引對之間子數(shù)組中值的 Numpy 總和的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

假設(shè)我有一個數(shù)組 A.我有一系列索引對 (a1, b1), (a2, b2) ... (an, bn)

Suppose I have an array A. I have a series of index pairs (a1, b1), (a2, b2) ... (an, bn)

我想獲得這些對之間元素的所有總和.即

I want to obtain all the sums of the elements between those pairs. i.e.

sum(A[a1:b1]), sum(A[a2:b2]), sum(A[a3:b3]) ...

就運行時而言,最有效的方法是什么?

In terms of run-time, what's the most efficient way of doing this?

謝謝!

推薦答案

假設(shè)您的索引對存儲在形狀為 (n, 2) 的 NumPy 數(shù)組 indicesn 相當大,最好避免任何 Python 循環(huán):

Assuming your index pairs are stored in a NumPy array indices of shape (n, 2) and n is fairly large, it is probably best to avoid any Python loop:

c = numpy.r_[0, A.cumsum()][indices]
sums = c[:,1] - c[:,0]

這篇關(guān)于索引對之間子數(shù)組中值的 Numpy 總和的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Sum values in a dict of lists(列表字典中的總和值)
How to sum numbers from a text file in Python(如何在 Python 中對文本文件中的數(shù)字求和)
What is a subtraction function that is similar to sum() for subtracting items in list?(什么是類似于 sum() 的減法函數(shù),用于減去列表中的項目?)
Python equivalent of sum() using xor()(Python 等價于 sum() 使用 xor())
sum matrix columns in python(python中的求和矩陣列)
sum of N lists element-wise python(N個列表元素的總和python)
主站蜘蛛池模板: 欧美日韩亚洲国产综合 | 有码一区| 搞黄视频免费看 | 日韩成人在线观看 | 一级毛片观看 | 91aiai| 97久久精品午夜一区二区 | 国产亚洲精品精品国产亚洲综合 | 欧美久久影院 | 手机av在线 | 三级黄色网址 | 久久一级| 皇色视频在线 | 亚洲欧美日韩精品久久亚洲区 | 国产一区不卡 | 九九热这里 | 欧美午夜精品久久久久久浪潮 | 99一区二区 | 毛片一区二区 | 成人一区二区三区在线观看 | 国产乱码精品1区2区3区 | 亚洲国产精品一区二区三区 | 久久伊人在 | 亚洲在线一区二区 | 中文字幕欧美日韩一区 | 人人爽人人爽人人片av | 不卡视频一区二区三区 | 亚洲精品中文字幕在线 | 日韩精品成人av | 理伦毛片 | 91精品国产99 | 美女日皮网站 | 亚洲免费在线 | 久草.com| 国产一区中文字幕 | 久色一区 | 国产激情网站 | 欧美精品欧美精品系列 | 一区二区三区四区视频 | 91在线看片 | 99热精品久久|