【发布时间】:2016-12-08 00:02:48
【问题描述】:
import numpy as np
newResidues = [1, 2, 3, 4, 5]
newI = [[1,0,1,0,1],[1,1,0,0,0],[1,0,0,1,0]]
sqrt = 10
templist = []
from itertools import compress
for i in newI:
valuesofresidues = list(compress(newResidues, i))
templist = valuesofresidues
print templist
这会返回
[1, 3, 5]
[1, 2]
[1, 4]
现在,让我们占据第一行,[1,3,5]
我需要做以下操作
pow((sqrt + 1),2) + pow((sqrt + 3), 2) + pow((sqrt + 5),2) 并分别返回所有行的总和。让它返回
515
265
317
我尝试添加一个嵌套的 for 循环
for temp in range(n):
x = templist[temp]
xsquare = pow(sqrt+x,2)
但它没有按我需要的方式工作。 任何帮助将不胜感激,谢谢!
【问题讨论】:
-
请将 "not working the way I need it to" 替换为 minimal reproducible example。
标签: python list multiplication