Python Membership Initialisation

Question:

I fail to define an array in my InitializeMembershipWeight function. I am currently working on a C-Means clustering algorithm.


#Membership Initialisation
def initializeMembershipWeights():

  weight = np.random.dirichlet(np.ones(k),n)
  weight_array = np.array(weight)
  return weight_array


print(weight_array)

NameError                                 
Traceback (most recent call last)
<ipython-input-114-70f058bffa58> in <module>
----> 1 print(weight_array)

NameError: name 'weight_array' is not defined
Asked By: pc419

||

Answers:

you need to save what the function outputs, then you can print it. Like this

def initializeMembershipWeights():

  weight = np.random.dirichlet(np.ones(k),n)
  weight_array = np.array(weight)
  return weight_array

weight_array = initializeMembershipWeights()
print(weight_array)
Answered By: A Simple Programmer
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.