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

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為具有 1 個值或 0 的列表的列表計算 st.dev 和均值

為具有 1 個值或 0 的列表的列表計算 st.dev 和均值

茅侃侃 2022-11-29 15:31:30
我有這個列表列表:fall_2_gpa = [[4.0, 3.4175, 3.1675, 3.2475, 3.25, 3.2475, 3.3325, 3.585, 3.5825, 3.3325, 3.5, 3.585, 3.8325, 3.165, 3.5025, 3.835, 3.5, 3.4175, 3.6675, 3.165, 3.25, 3.4175, 3.9175, 3.6675, 3.8325, 3.2475, 3.4175, 3.4175, 3.5825, 3.415, 3.5825, 3.585, 3.25, 3.4175, 3.6675, 3.3325, 3.5, 3.165, 3.3325, 3.6675, 3.6675], [3.5], [3.1675, 3.4175, 3.5, 3.6675, 2.5, 2.835, 3.585, 3.4175, 3.25, 3.4175, 3.1675, 3.75], [2.6675, 3.0], [3.0825, 3.665, 3.6675, 3.3325, 3.3325, 3.415], [3.3325, 3.415, 3.415, 3.415, 3.75, 3.75, 3.665, 3.6675, 3.6675, 3.5825, 3.5825, 3.9175, 3.4175, 3.6675, 3.5, 3.5825, 3.585, 3.6675, 3.665, 3.4175, 3.585, 3.4175, 3.415, 3.75, 4.0, 3.5, 3.6675, 3.25, 3.585, 3.3325, 3.4175, 3.5, 3.6675, 3.7525, 3.3325, 3.835, 3.335, 3.665, 3.5, 3.6675, 3.585, 3.75, 3.75, 3.5, 3.415, 3.0825, 3.6675, 3.2475, 3.2475, 3.335, 3.9175, 3.75, 3.75, 3.75, 3.585, 3.585, 3.4175, 3.25, 3.3325, 3.5, 3.25, 3.75, 2.835, 3.1675, 2.5825, 3.25, 3.5825, 2.915, 2.8325, 2.5, 3.0825, 3.3325, 2.8325, 3.25, 2.8325, 3.335], [3.5, 3.3325, 3.6675], [3.165, 3.4175, 3.4975, 3.25], [3.5825, 3.5, 3.4175, 3.75, 3.335, 3.335, 3.415, 3.5, 3.6675, 3.165, 3.6675, 3.4975, 3.9175, 3.6675, 3.4175, 3.25, 3.3325, 3.585, 3.835, 3.2475, 3.335, 3.75, 3.5825, 3.5, 3.4175, 3.5, 3.75, 3.5825, 3.585, 3.335, 3.5825, 3.5825, 3.3325, 3.75, 3.5, 3.6675, 3.3325, 3.5825, 3.4175, 3.415, 3.585, 3.75, 3.415, 3.4175, 3.25, 3.4175, 3.415, 3.415, 3.75, 3.9175, 3.8325, 3mean_fall_2 = [statistics.mean(d) for d in fall_2_gpa if d != 0] stdev_fall_2 = [statistics.stdev(d) for d in fall_2_gpa if d != 0]但我不斷收到此錯誤:statistics.StatisticsError:方差至少需要兩個數(shù)據(jù)點我相信我得到這個是因為一些子列表只有 1 個值并且不超過 2 個。對于另一個列表我得到這個錯誤:statistics.StatisticsError: mean 至少需要一個數(shù)據(jù)點這可能意味著它找到了一個空的子列表?有辦法解決這些問題嗎?我需要 st.dev 并且意味著要計算所有內(nèi)容,無一例外。
查看完整描述

1 回答

?
守候你守候我

TA貢獻(xiàn)1802條經(jīng)驗 獲得超10個贊

fall_2_gpa 列表包含一些大小為 1 的列表,這些列表將傳遞給 statistics.stdev() 函數(shù)。但是,statistics.stdev() 期望參數(shù)至少有兩個項目。因此,我們可以在處理列表項時添加一個條件來檢查列表的大小:-

stdev_fall_2 = [statistics.stdev(d) for d in fall_2_gpa if d != 0 and len(d)>1]

以類似的方式,我們也可以指示函數(shù)在列表大小小于 2 時使用一些默認(rèn)值。

使用以下內(nèi)容在 else 條件下添加 0:

stdev_fall_2 = [statistics.stdev(d) if d != 0 and len(d) > 1 else 0 for d in fall_2_gpa]


查看完整回答
反對 回復(fù) 2022-11-29
  • 1 回答
  • 0 關(guān)注
  • 113 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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