好的,我在python中有一个数组。此数组将索引保存到另一个数组。我从这个数组中删除了我想保留的索引。
select * from
(select adverts.ad_name as ad_1 from adverts join ad_slots on ad_1 =
adverts.ad_id),
(select adverts.ad_name as ad_2 from adverts join ad_slots on ad_2 =
adverts.ad_id),
(select adverts.ad_name as ad_3 from adverts join ad_slots on ad_3 =
adverts.ad_id),
(select adverts.ad_name as ad_4 from adverts join ad_slots on ad_4 =
adverts.ad_id);
我们打电话给stations = [1,2,3]
主阵列。它有5列,我删除了第1列和第5列,并将其余列放在名为x
的数组中。
我希望能够创建一个if语句,其中排除来自站的值。所以我只是想找到其中index数组中的索引为0而其他索引(0和4)不为0的实例数(天)。
我该怎么做呢?到目前为止我有这个,但它似乎不正确。
stations
答案 0 :(得分:0)
我认为您的问题陈述不是很清楚,但是如果您想要x cols以便排除工作站中包含的索引,那么就这样做。
excluded_station_x = [col for i, col in enumerate(x) if i not in stations]
这是一个列表理解,它是通过遍历迭代来构建新列表的一种方式。它和写作一样
excluded_station_x = []
for i, col in enumerate(x):
if i not in stations:
excluded_station_x.append(col)
当我们遍历列表时,enumerate()产生每个元素的值和索引。
根据要求,我将不加枚举。 你也可以只删除每个坏指数,虽然我不喜欢这个,因为它会改变原始列表。
for i in stations:
del x[i]