Select Git revision

tuhe authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
looping.py 1.64 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:
* consider n0
* alpha > 0
:param n0:
:param alpha:
:param K:
:param N:
:return:
"""
# TODO: 6 lines missing.
raise NotImplementedError("Implement function body")
return t+1
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):
# Insert your code here
return np.mean( [r for r in measuredRate if lowerBound < r < upperBound] )
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])