i don't understand this python class

joseph pareti joepareti54 at gmail.com
Mon Jun 29 13:14:19 EDT 2020


I have piece of code with constructs as follows:

*class* *SentimentNetwork**:*

    *def* __init__*(*self*,* reviews*,* labels*,* hidden_nodes *=* 10*,*
learning_rate *=* 0.1*):*



        np*.*random*.*seed*(*1*)*



       self*.*init_network*(**len**(*self*.*review_vocab*),*hidden_nodes*,*
1*,* learning_rate*)*







    *def* init_network*(*self*,* input_nodes*,* hidden_nodes*,* output_nodes
*,* learning_rate*):*

        # Store the number of nodes in input, hidden, and output layers.

        self*.*input_nodes *=* input_nodes

        self*.*hidden_nodes *=* hidden_nodes

        self*.*output_nodes *=* output_nodes

which makes me think about the redundant usage of* init_network:*

   1. as a method, AND
   2. as a property

So far I have only seen codes where the 2 things are separated, e.g. :

*import* insurance *as* ins

*class* *Vehicle**:*

    *def* __init__*(*self*,* speed*,* make*):*

        self*.*speed *=* speed

        self*.*make *=* make

*class* *car**(*Vehicle*):*

    *def* __init__*(*self*,* speed*,* make*):*

        Vehicle*.*__init__*(*self*,* speed*,* make*)*

        self*.*insurance *=* ins*.*calc*(*make*)*

    *def* show_out*(*self*):*

        *print**(*'vehicle is '*,*self*.*make*,*' insurance premium '*,*self
*.*insurance*)*

    *def* claim*(*self*,* discount*):*

        X *=* self*.*insurance *+* discount

        *return* X


And hence I am not sure about the behavior of the first code in this email.
-- 
Regards,
Joseph Pareti - Artificial Intelligence consultant
Joseph Pareti's AI Consulting Services
https://www.joepareti54-ai.com/
cell +49 1520 1600 209
cell +39 339 797 0644


More information about the Python-list mailing list