mylist = [
[2, 4],
[3, 1],
[-2, 5],
[6.2, 4],
[1, 4]
]
type(mylist)
len(mylist)
mylist[3][0]
import numpy as np
myarray = np.array(mylist)
display(myarray)
count = 0
for i in mylist:
if i[-1] == 4:
count += 1
print(count)
myarray[:,-1]
myarray[:,-1] == 4
sum(myarray[:,-1] == 4)
import numpy as np
import pickle
with open("wkst2-starter.pickle", "rb") as f:
arr = pickle.load(f)
type(arr)
arr.shape
x = arr[:,4]
type(x)
sum(x == 10)
arrsub = arr[x == 10]
arrsub.shape
a = arrsub.shape[0]
x = (arr == 40)
y = x.sum(axis=1)
z = y > 0
b = np.sum(z)
ansdict = {"names": [Guo Cheng, Junhong Fu, Maryam Kasiri], "a": a, "b": b}
with open("wkst2-ans.pickle", "wb") as f:
pickle.dump(ansdict, f)