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

N個列表元素的總和python

sum of N lists element-wise python(N個列表元素的總和python)
本文介紹了N個列表元素的總和python的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

有沒有一種簡單的方法來計算 Python 中 N 個列表的元素總和?我知道如果我們有n個列表定義(調(diào)用第i個列表c_i),我們可以這樣做:

Is there an easy way to compute the element-wise sum of N lists in python? I know if we have n lists defined (call the ith list c_i), we can do:

z = [sum(x) for x in zip(c_1, c_2, ...)]

例如:

c1 = [1,2]
c2 = [3,4]
c3 = [5,6]
z  = [sum(x) for x in zip(c1,c2,c3)]

這里z = [9, 12]

但是如果我們沒有定義 c_i 而是在列表 C 中有 c_1...c_n 怎么辦?

But what if we don't have c_i defined and instead have c_1...c_n in a list C?

如果我們只有 C,有沒有類似的方法可以找到 z?

Is there a similar way to find z if we just have C?

我希望這很清楚.

已解決:我想知道 * 運算符是什么意思...謝謝!

resolved: I was wondering what the * operator was all about...thanks!

推薦答案

這樣做:

[sum(x) for x in zip(*C)]

在上面,Cc_1...c_n的列表.正如評論中的 鏈接 中所述(感謝@kevinsa5!):

In the above, C is the list of c_1...c_n. As explained in the link in the comments (thanks, @kevinsa5!):

* 是splat"運算符:它將一個列表作為輸入,并將其擴(kuò)展為函數(shù)調(diào)用中的實際位置參數(shù).

* is the "splat" operator: It takes a list as input, and expands it into actual positional arguments in the function call.

有關(guān)更多詳細(xì)信息,請查看 文檔,在解包參數(shù)列表"下,還閱讀了有關(guān) 調(diào)用 (謝謝@abarnert!)

For additional details, take a look at the documentation, under "unpacking argument lists" and also read about calls (thanks, @abarnert!)

這篇關(guān)于N個列表元素的總和python的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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中的求和矩陣列)
Python sum() function with list parameter(帶有列表參數(shù)的 Python sum() 函數(shù))
主站蜘蛛池模板: 免费一区二区三区 | 久久精品久久精品 | 99精品在线观看 | 天天操网 | 欧美在线观看视频 | 一级黄色片在线观看 | 色婷婷导航 | 天天看天天干 | 成人av一区二区三区在线观看 | 闷骚老干部cao个爽 欧美区一区二 | 国产三级成人 | 欧美日韩高清在线 | 日韩一级黄色片 | 天天操夜夜| 在线观看一区 | 免费看a级片 | 精品理论片 | 欧美老少妇 | 亚洲一二区 | 国产欧美一区二区精品忘忧草 | 伊人9999 | 福利视频网站 | 少妇性bbb搡bbb爽爽爽欧美 | 日韩中文字幕免费 | 极品av在线 | 超碰123 | 91久久综合亚洲鲁鲁五月天 | 国产超碰人人模人人爽人人添 | 美日韩精品 | 每日更新av| 日韩黄色在线视频 | www黄色片| 久热在线视频 | 亚洲国产欧美在线 | 国产精品二区在线观看 | 人人爱人人插 | 亚洲一级二级三级 | www.4hu95.com四虎 丰满岳乱妇一区二区 | 午夜看片 | 日韩免费一区二区三区 | 91狠狠 |