python列表元素都加倍,Python列表元素明智的条件增量

I have been searching this for a while, basically I am trying to conditionally increment a list of element by another list, element-wise...

my code is following, but is there a better way to do it? list comprehension, map??

I think a element-wise operator like ~+= from http://www.python.org/dev/peps/pep-0225/ would be really good, but why is it deferred?

for i in range(1,len(s)):

if s[i]

s[i]+=p[i]

based on some good feedbacks from you guys I have recoded to the following

i=s

s[i]+=p[i]

and s,p are both arrays.

p.s still slow than matlab 5 times for one of my code.

解决方案

If you don't want to create a new array, then your options are:

What you proposed (though you might want to use xrange depending on the python version)

Use Numpy arrays for s and p. Then you can do something like s[s

Use Cython to speed up what you've proposed.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值