Select Git revision
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
looping.py 1.73 KiB
import numpy as np
import itertools
def bacteriaGrowth(n0, alpha, K, N):
"""
Calculate time until bacteria growth exceed N starting from a population of n0 bacteria.
hints:
* You need to update the number of bacteria n0 within a loop
"""
# TODO: 7 lines missing.
raise NotImplementedError("Implement function body")
return t
def clusterAnalysis(reflectance):
reflectance = np.asarray(reflectance)
I1 = np.arange(len(reflectance)) % 2 == 1
while True:
m = np.asarray( [np.mean( reflectance[~I1] ), np.mean( reflectance[I1] ) ] )
I1_ = np.argmin( np.abs( reflectance[:, np.newaxis] - m[np.newaxis, :] ), axis=1) == 1
if all(I1_ == I1):
break
I1 = I1_
return I1 + 1
def fermentationRate(measuredRate, lowerBound, upperBound):
"""
Compute and return the mean value of the rates in 'measuredRate'
which falls within lowerBound and upperBound.
"""
mean_value = np.mean( [r for r in measuredRate if lowerBound < r < upperBound] )
return mean_value
def removeIncomplete(id):
"""
Hints:
* Take a look at the example in the exercise.
"""
id = np.asarray(id)
id2 = []
for i, v in enumerate(id):
if len( [x for x in id if int(x) == int(v) ] ) == 3:
id2.append(v)
return np.asarray(id2)
if __name__ == "__main__":
# I = clusterAnalysis([1.7, 1.6, 1.3, 1.3, 2.8, 1.4, 2.8, 2.6, 1.6, 2.7])
# print(I)
print(fermentationRate(np.array([20.1, 19.3, 1.1, 18.2, 19.7, 121.1, 20.3, 20.0]), 15, 25))
# print(removeIncomplete(np.array([1.3, 2.2, 2.3, 4.2, 5.1, 3.2, 5.3, 3.3, 2.1, 1.1, 5.2, 3.1])))
# Problem 1: Write a function which add two numbers
# clusterAnalysis([2, 1, 2, 4, 5])