新手,基础差
当z2为False时,输出z1对应的位置上的值
z1=[1,2,3,4,5,6,7,8,9]
z2=[True,False,False,True,True,True,True,True,False]
z1=z1[~x for x in z2] #这句有问题
print z1
因为我看到一段程序,是这样表达的:
x=x[~sp.isnan(y)]
y=y[~sp.isnan(y)]
不知道有什么不同
1
cc7756789 2015-07-27 19:05:14 +08:00
>>> for x in zip(z1, z2):
... if not x[1]: ... print x[0] ... 2 3 9 >>> n = 0 >>> for x in z2: ... if not x: ... print z1[n] ... n += 1 ... 2 3 9 |
2
mianju 2015-07-27 20:33:22 +08:00
```
for i in range(len(z1)): if not z2[i]: print z1[i] ``` 应该也可以 |
3
mianju 2015-07-27 20:33:56 +08:00
缩进没弄好,抱歉就将就看看吧> <
|
4
scream7 2015-07-27 20:50:49 +08:00
z1 = [x for x,y in zip(z1,z2) if y]
|
5
wffett OP |
6
BooksE 2015-07-27 22:20:14 +08:00
lz是从R转过来的么..
|