0

I just wrote this class in python to extract some features from a dataset :

class Features :

    def __init__ (self , data):
        self.data = data 

    def Energy (self) :
        energy=float (sum(self.data**2))
        return (energy)

    def Power (self):
        power = float (sum(self.data**4))
        return power

    def NonlinearEnergy (self) :
        limit1=0
        NLE = 0
        while limit1 < len(self.data):
            NLE += float ((-self.data[limit1]*self.data[limit1-2] + self.data[limit1-1]**2 ))
            limit1+=1

        return NLE

    def CurveLength (self):
        limit2=0
        CL=0
        while limit2 < len(self.data):
            CL += float ((self.data[limit2] - self.data[limit2-1]))
            limit2+=1

and when I try to see the result of a dataset's object, the result appears Like that :

<bound method Features.Energy of <__main__.Features object at 0x0000028952C105C0>>

My question is: how can I see the result numerically, or in other words, how can I see my actual result?

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Zuha
  • 19
  • 1
  • 3
  • 1
    What code do you use to see the result? – Mitchell van Zuylen Dec 03 '17 at 20:53
  • 5
    The output you show suggests you're just accessing the `Energy` method, without calling it. Try using `some_feature_object.Energy()` instead of `some_feature_object.Energy` and you should get a float. If you *really* want the computed values to work like attributes, you could instead decorate the methods with `@property`, but I'm not sure that's really necessary here. – Blckknght Dec 03 '17 at 20:59
  • https://stackoverflow.com/questions/1535327/how-to-print-a-class-or-objects-of-class-using-print – Yasser Hussain Dec 03 '17 at 21:01

1 Answers1

0

This problem happens as a result of calling a method without brackets.

Take a look at the example:

obj = Features(data)
print (obj.Energy())

So, first create a new object for your class and then call your method as obj.Energy(). This is because, whenever an object calls its method, the object itself is passed as the first argument. So, obj.Energy() translates into Features.Energy(obj)

Kian
  • 1,319
  • 1
  • 13
  • 23