Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

NameError: name 'the_shape' is not defined

I get the following error when I try to import my KMeans module containing the class named KMeansClass. The KMeans.py module has the following structure:

import numpy as np 
import scipy
class KMeansClass:
    #takes in an npArray like object
    def __init__(self,dataset,the_shape=5):
        self.dataset=dataset
        self.mu = np.empty(shape=the_shape)

and in ipython when I try import KMeans

I get the NameError: name 'the_shape' is not defined

I am really new to python OOP and don't know why this is happening as all I'm doing is passing arguments to init and assigning those arguments to instance variables.

Any help would be appreciated.

Thanks in advance!

Full Traceback:

NameError                                 Traceback (most recent call last)
<ipython-input-2-44169aae5584> in <module>()
----> 1 import kmeans

/Users/path to file/kmeans.py in <module>()
      1 import numpy as np
      2 import scipy
----> 3 class KMeansClass:
      4         #takes in an npArray like object
      5         def __init__(self,dataset,the_shape=5):

/Users/path_to_file/kmeans.py in KMeansClass()
      5         def __init__(self,dataset,the_shape=5):
      6                 self.dataset=dataset
----> 7         self.mu = np.empty(shape=the_shape)
      8 
      9 

NameError: name 'the_shape' is not defined
share|improve this question
    
The code you've shown seems fine. Can you edit to include a full traceback of your exception? It seems like it must be coming from some other code. –  Blckknght Nov 4 '13 at 20:26
5  
Note the indentation: looks like you are mixing tabs and spaces for indentation. Don't do that; better to stick to just spaces (configure your editor to replace tabs with spaces for indentation). –  Martijn Pieters Nov 4 '13 at 20:30
    
I added the traceback. Still unable to figure it out. –  user1009091 Nov 4 '13 at 20:30
    
To be certain, run your code with python -tt scriptname.py. –  Martijn Pieters Nov 4 '13 at 20:30
4  
This question appears to be off-topic because it is about tab/space issues with the OPs code and not the code posted here –  Mark Nov 4 '13 at 20:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.