Python Forum
Loop does not work in python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Loop does not work in python
#1
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:

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])))
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.

Can anyone help me out? Thank you in advance for your help!
Reply


Messages In This Thread
Loop does not work in python - by Ola92 - Jan-12-2020, 10:12 AM
RE: Loop does not work in python - by Larz60+ - Jan-12-2020, 03:14 PM
RE: Loop does not work in python - by Ola92 - Jan-12-2020, 06:22 PM
RE: Loop does not work in python - by ibreeden - Jan-12-2020, 07:34 PM
RE: Loop does not work in python - by Ola92 - Jan-12-2020, 07:42 PM
RE: Loop does not work in python - by Ola92 - Jan-12-2020, 08:50 PM
RE: Loop does not work in python - by sandeep_ganga - Jan-13-2020, 05:43 AM
RE: Loop does not work in python - by Ola92 - Jan-13-2020, 10:18 AM
RE: Loop does not work in python - by sandeep_ganga - Jan-13-2020, 10:41 AM
RE: Loop does not work in python - by Ola92 - Jan-13-2020, 12:20 PM
RE: Loop does not work in python - by sandeep_ganga - Jan-13-2020, 03:43 PM
RE: Loop does not work in python - by Ola92 - Jan-13-2020, 06:27 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Issues with while loop, while (var != 0): does not work, but while (var !=''): works danilo 2 2,117 Apr-15-2019, 12:08 AM
Last Post: danilo
  Hi, my loop yes/no part doesn't work and I really need help fordxman5 2 2,668 Feb-14-2018, 11:38 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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