【问题标题】:What is the similar python code for this matlab code " find( conv ( variable, [1 0 1] == 2 ) ) ", where variable is a list of 0's and 1's [duplicate]这个matlab代码“find(conv(变量,[1 0 1] == 2))”的类似python代码是什么,其中变量是0和1的列表[重复]
【发布时间】:2020-09-28 13:36:59
【问题描述】:
我有一个清单
series = [0 1 1 0 1 0 1 0 0 0 1 .....]
我希望找到两个 1 被两个索引隔开的索引 ex。 [0 1 0 1] 现在位置是 1 和 3。现在我希望为更大的列表做同样的事情。
为此目的的Matlab代码是
find(conv(series,[1 0 1])==2)
【问题讨论】:
标签:
python
python-3.x
list
matlab
【解决方案1】:
见下文。
这就是你要找的吗?
s = [0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1]
data = []
for x in range(0,len(s)-1):
if x > 0:
if s[x-1] == 1 and s[x] != 1 and s[x+1] == 1:
data.append(x)
print(data)
输出
[3, 5]