Skip to content

Commit 44c2f88

Browse files
committed
update day5 homework
1 parent 7281621 commit 44c2f88

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

D04/homework.py

+6
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@
99
# print(ans1)
1010
Ans = [ A for A in ans1 if A==True ]
1111
print('有 %d 個學生英文成績比數學成績高' % len(Ans))
12+
print('有 %d 個學生英文成績比數學成績高' % np.sum(Ans))
1213

1314
#2.是否全班同學最高分都是國文?
1415
ans2 = np.greater(chinese_score,english_score,math_score )
1516
# print(ans2)
1617
Ans = [ A for A in ans2 if A==1 ]
1718
print('是否全班同學最高分都是國文: %s' % ( len(Ans)==6) )
19+
print('是否全班同學最高分都是國文: %s' % ans2.any() )
1820

21+
ch_greater_ma = np.greater(chinese_score,math_score)
22+
ch_greater_en = np.greater(chinese_score,english_score)
23+
print(np.logical_and(ch_greater_ma,ch_greater_en))
24+
print(np.logical_and(ch_greater_ma,ch_greater_en).all())

D05/homework.py

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import numpy as np
2+
3+
english_score = np.array([55,89,76,65,48,70])
4+
math_score = np.array([60,85,60,68,np.nan,60])
5+
chinese_score = np.array([65,90,82,72,66,77])
6+
7+
#上 3 列共六位同學的英文、數學、國文成績,第一個元素代表第一位同學,舉例第一位同學英文 55 分
8+
# 、數學 60 分、國文 65 分,今天第五位同學因某原因沒來考試,導致數學成績缺值
9+
def Tavg():
10+
EngAvg = np.average(english_score)
11+
MathAvg = np.nanmean(math_score)
12+
ChtAvg = np.average(chinese_score)
13+
print('各科成績平均 %s' % EngAvg,MathAvg,ChtAvg)
14+
15+
def Tmax():
16+
EngMax = np.nanmax(english_score)
17+
MathMax = np.nanmax(math_score)
18+
ChtMax = np.nanmax(chinese_score)
19+
print('各科成績最大值 %s' %EngMax,MathMax, ChtMax)
20+
21+
def Tmin():
22+
EngMin = np.nanmin(english_score)
23+
MathMin = np.nanmin(math_score)
24+
ChtMin = np.nanmin(chinese_score)
25+
print('各科成績最小值 %s' %EngMin,MathMin, ChtMin)
26+
27+
def Tstd():
28+
EngStd = np.nanstd(english_score)
29+
MathStd = np.nanstd(math_score)
30+
ChtStd = np.nanstd(chinese_score)
31+
print('各科成績標準差 %s' %EngStd,MathStd, ChtStd)
32+
33+
print(" English Math Chinese")
34+
#1. 請計算各科成績平均、最大值、最小值、標準差,其中數學缺一筆資料可忽略?
35+
Tavg()
36+
Tmax()
37+
Tmin()
38+
Tstd()
39+
40+
#2. 第五位同學補考數學後成績為 55,請計算補考後數學成績平均、最大值、最小值、標準差?
41+
math_score[4]=55
42+
Tavg()
43+
Tmax()
44+
Tmin()
45+
Tstd()
46+
47+
#3. 用補考後資料找出與國文成績相關係數最高的學科?
48+
E=np.corrcoef(english_score, chinese_score)
49+
M=np.corrcoef(math_score, chinese_score)
50+
if np.maximum(E,M).all() :
51+
print("與國文成績相關係數最高的學科 is English")
52+
else:
53+
print("與國文成績相關係數最高的學科 is Math")

0 commit comments

Comments
 (0)