第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

蟒蛇元組刪除南

蟒蛇元組刪除南

ABOUTYOU 2022-09-13 19:25:29
我有一個(gè)包含元組的列表。我需要?jiǎng)h除任何包含nan的元組。我該怎么做?楠的類型是數(shù)學(xué)。它返回 True。math.isnan(tmp[1][1][1])我試過(guò)這個(gè),它不起作用:import mathres = [t for t in tmp if not any(isinstance(n, float) and float('nan') for n in t)]print(res)我也試過(guò)這個(gè),它不起作用:nans = {np.nan, math.nan, float('nan')}[x for x in tmp if not nans.intersection(x)] 下面是一個(gè)元組示例tmp = [[(0, 1.0),  (5, nan),  (10, 1.0),  (15, nan),  (20, 1.0),  (25, nan),  (30, 1.0),  (35, nan),  (40, 0.9808612440191388),  (45, nan),  (50, 0.9719298245614035),  (55, nan),  (60, 0.9712918660287081),  (65, nan),  (70, 0.8947368421052632),  (75, nan),  (80, 0.956140350877193),  (85, nan),  (90, 0.6140350877192983)], [(0, 0.9635627530364372),  (5, nan),  (10, 1.0),  (15, nan),  (20, 0.9924812030075187),  (25, nan),  (30, 1.0),  (35, nan),  (40, 0.9808612440191388),  (45, nan),  (50, 0.9508771929824561),  (55, nan),  (60, 0.9617224880382775),  (65, nan),  (70, 0.8173374613003096),  (75, nan),  (80, 0.8464912280701754),  (85, nan),  (90, 0.5614035087719298)]]
查看完整描述

1 回答

?
暮色呼如

TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超9個(gè)贊

您可以使用嵌套列表理解來(lái)執(zhí)行此操作。循環(huán)訪問(wèn)列表的每個(gè)子列表,循環(huán)訪問(wèn)每個(gè)元組,檢查元組是否包含 .nan


[[tup for tup in sublist if not any(map(math.isnan, tup))] for sublist in tmp]

# returns:

[[(0, 1.0),

  (10, 1.0),

  (20, 1.0),

  (30, 1.0),

  (40, 0.9808612440191388),

  (50, 0.9719298245614035),

  (60, 0.9712918660287081),

  (70, 0.8947368421052632),

  (80, 0.956140350877193),

  (90, 0.6140350877192983)],

 [(0, 0.9635627530364372),

  (10, 1.0),

  (20, 0.9924812030075187),

  (30, 1.0),

  (40, 0.9808612440191388),

  (50, 0.9508771929824561),

  (60, 0.9617224880382775),

  (70, 0.8173374613003096),

  (80, 0.8464912280701754),

  (90, 0.5614035087719298)]]


查看完整回答
反對(duì) 回復(fù) 2022-09-13
  • 1 回答
  • 0 關(guān)注
  • 125 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)