Python Forum
Looping exercise Bacteria growth
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Looping exercise Bacteria growth
#6
Yes, I have noticed that mistake in my code. Thank you again for your help!

I need help with one more exercise... It seems that my loop function does not work and I do not understand why..
I get a result 2 and I should get this list of number:2 2 2 2 1 2 1 1 2 1.

My code:
[python]
import numpy as np
import math
def clusterAnalysis(reflectance):
ref=np.size(reflectance)
even1=np.any(ref %2==0)
uneven1=np.any(ref%2>0)
even2="2"
uneven2="1"
even3=(np.mean(even1))
uneven3=(np.mean(uneven1))
while ref==even1:
clusterAssigments="2"
if ref==uneven1:
clusterAssigments="1"
else:ref==even1 and ref==uneven3
clusterAssigments="2"
return clusterAssigments
print(clusterAnalysis(np.array([1.7, 1.6, 1.3, 1.3, 2.8, 1.4,
2.8, 2.6, 1.6, 2.7])))
[python]
The assigment:
The clustering algorithm
Given a set of N measurements, (r1, r2, . . . , rN ), we will initially assign the odd-numbered measurements to
class 1 and the even numbered measurements to class 2. Then the following two steps are repeated:
• Update step: Compute the mean value (average) of the measurements within each cluster.
• Assignment step: Assign each measurement to the cluster with the closest mean value. In case of a tie,
assign the measurement to cluster 1.
Repeat the above steps until the cluster assignments do not change. It can not be determined in advance how
many steps will be needed before the clustering assignment stabilizes.
Problem definition
Create a function that takes as an input a vector of reflectance measurements and returns a vector of cluster
assignments computed using the algorithm described above.

Thank you in advance for your help!
Reply


Messages In This Thread
Looping exercise Bacteria growth - by Ola92 - Jan-10-2020, 11:28 AM
RE: Looping exercise Bacteria growth - by perfringo - Jan-10-2020, 11:38 AM
RE: Looping exercise Bacteria growth - by Ola92 - Jan-10-2020, 01:09 PM
RE: Looping exercise Bacteria growth - by Ola92 - Jan-11-2020, 11:09 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020