From 7b21727285e50b0b050c4ddd70d07542229c5366 Mon Sep 17 00:00:00 2001 From: pants Date: Mon, 21 Sep 2026 14:17:03 -0700 Subject: init --- python/atms-310/midterms/MT 1.pdf | Bin 0 -> 186502 bytes python/atms-310/midterms/midterm1.py | 58 +++++++++++++++++++++++++++ python/atms-310/midterms/midterm2.py | 63 ++++++++++++++++++++++++++++++ python/atms-310/midterms/mt2_datafile.txt | 1 + 4 files changed, 122 insertions(+) create mode 100755 python/atms-310/midterms/MT 1.pdf create mode 100755 python/atms-310/midterms/midterm1.py create mode 100755 python/atms-310/midterms/midterm2.py create mode 100755 python/atms-310/midterms/mt2_datafile.txt (limited to 'python/atms-310/midterms') diff --git a/python/atms-310/midterms/MT 1.pdf b/python/atms-310/midterms/MT 1.pdf new file mode 100755 index 0000000..2200498 Binary files /dev/null and b/python/atms-310/midterms/MT 1.pdf differ diff --git a/python/atms-310/midterms/midterm1.py b/python/atms-310/midterms/midterm1.py new file mode 100755 index 0000000..f48bf90 --- /dev/null +++ b/python/atms-310/midterms/midterm1.py @@ -0,0 +1,58 @@ +## 1 +a = 1 +b = 2 +c = -3 + +# a +# ((a=c)) and (a==1) +# a is less than b, and a is greater than or equal to 3, so the or is true. a also equals 1, so the and is true. overall, this statement is true. + +# b +# ((a != b) and (a <= c)) or (a <= c) +# a does not equal b, but a is not less than or equal to c, so the and is false. +# a is still not less than or equal to c, so the or is also false, making the statement as a whole false. + +# c +# ((a == c) or (b > c)) and (-a*b < c) +# a does not equal c, but b is greater than c, so the or is true. -a*b=-2 which is greater than c, so the and is false, making the whole statement false. + +# d +# (a <= 1) and ((b != c*a) or (b == a*b)) +# a is less than or equal to 1. b does not equal c*a, but b does equal a*b, overall true + +## 2 + +import numpy as np + +data = np.zeros((4,3)) +data = np.array([[7.6, 288.3, 278.4], [6.3, 278.6, 271.3], [5.2, 272.1, 265.3],[3.7, 250.3, 230.4]]) + +def atmo(x): + hpa = x[0:5,0]*133.322 + dew = np.zeros((4)) + dewdep = x[0:5,1]-x[0:5,2] + for i in range(len(dewdep)): + z = dewdep[i] + if z < 0: + raise ValueError('dewpoint depression negative, check temp and dewpoint values') + return hpa,dewdep + + +print(np.array(atmo(data))) + +# row 0 is pascals conversion, row 1 is dewpoint depression +# note: the given conversion factor seems to be from mmHg to pascals, instead of hectopascals. maybe im wrong. + +# 2(g) +# in order to account for 10 rows instead of 4, the only change needed would be to initialize an array 10 deep, and then actually populate it with the extra data. +# all operations within my function "atmo" are only dependent on start locations, so making the end of the array further away wouldnt matter. +# as for the for loop looking for negative dewdeps, that is iterative (slow i know) but can (and will) adapt to the length (depth) of the resulting array of dewdep values. +# ok no theres one more thing, I would also need to initialize a deeper array (10 instead of 4, this is inside of "atmo") for the dewdep values to be inserted into. theres probably a way to do this that gets the amount of rows in the actual data array, but i dont know how to do it yet. + +# 2(h) +# the only real problem that could plague the data is it either being zero or negative, and one way of verifying the datas integrity would be to iterate through all of it in a for loop before (next line) +# doing any calculations with it, looking for values less than or equal to 0. + +# BONUS +# I didnt actually study,(mb bro) I just reviewed the nonsensical syntax of numpy.zeros and how it needs two sets of parentheses. unthinkable. +# I use a 3440x1440 (21:9) monitor, sorry if alot of the text goes off screen \ No newline at end of file diff --git a/python/atms-310/midterms/midterm2.py b/python/atms-310/midterms/midterm2.py new file mode 100755 index 0000000..fd3405a --- /dev/null +++ b/python/atms-310/midterms/midterm2.py @@ -0,0 +1,63 @@ +import pandas as pd +import numpy as np +import scipy.stats as s + +# 1a. +fileobj = open("./mt2_datafile.txt", "r") + +# 1b. +datai = fileobj.readlines() +datam = datai[0] +dataf = datam.split(',') +print(dataf) + +# 1c. +dataa = np.array(dataf) +dataa = np.reshape(dataf,(3,7)) +print(dataa) + +# 1d. +for n in range(len(dataf)): + dataf[n] = int(dataf[n]) +print(dataf) + +print(np.mean(dataf)) +print(np.median(dataf)) +print(np.std(dataf)) +print(s.iqr(dataf)) + +# mean and median are close, no outliers +# stddev is quite small, suggesting consistent data +# iqr is larger than stddev, so the middle is more spread out than the rest (??? perhaps ???) + +# 2a. +students = {"name": ["garrus vakarian", "matilda bradbury", "cordelia vorkosigan", "kira nerys", "Jean-Luc Picard"],\ + "credits": [37,43,36,23,50], "GPA": [3.2,4.0,3.7,3.6,3.4], "Hometown": ["Palaven", "Whitestone","Vashnoi",\ + "Dahkur", "La Barre"]} + +# 2b. +# fyi: sdt stands for "superior data type" +sdt = pd.DataFrame(students) +print(sdt) +# beautiful. incredible. just amazing. + +# 2c. +sdt.set_index("name",inplace=True) + +# 2d. +print("kira's GPA:" + str(sdt.loc["kira nerys","GPA"])) + +# 2e. +sdt.loc["matilda bradbury","credits"] = 44 +print(sdt) + +# 2f. +print(sdt.credits.describe()) +print(sdt.GPA.describe()) + +# 2g. + +height = [10,23,-1,43,100] + +sdt["height (in meters)"] = height +print(sdt) diff --git a/python/atms-310/midterms/mt2_datafile.txt b/python/atms-310/midterms/mt2_datafile.txt new file mode 100755 index 0000000..8a3e298 --- /dev/null +++ b/python/atms-310/midterms/mt2_datafile.txt @@ -0,0 +1 @@ +1,4,7,3,7,8,3,2,7,4,8,7,3,9,5,8,3,7,3,8,5 \ No newline at end of file -- cgit v1.2.3