Hi Jeff, So I am new to Python programming, so some of the nuances I am not up on yet. My understanding is the self.x, etc. is used to initialize param arguments in the def __init__() method and in my case, the only argument in this method is start, there is no v for me to use self.v = v. v is used the work() and my_init() methods. At program startup work() calls my_init() method to get the initial values for the numpy array v (my_init() function will be called once only at startup when self.start is True). After initialization and v is passed back to the work(), the values in the numpy array v inside work will change on a sample to sample computation basis. My problem is how do I assign v its initial seed value at start up. If my program was simple with only one parameter v, I would initialize it inside the work() method, however, I have a bunch of other vector variables to initialize which is why I want to initialize all parameters inside a my_init() method that work() calls at startup.
Thanks for the help. George On Thu, Jan 14, 2021 at 8:14 AM Jeff Long <willco...@gmail.com> wrote: > You are already initializing self.start in exactly the same way you should > be initializing self.v, right? > > On Wed, Jan 13, 2021 at 10:46 PM George Edwards <gedwards....@gmail.com> > wrote: > >> Hi Jeff, >> >> Thanks for your answer. You are right, it crashes on the second call. >> >> So how do I write the program to initialize a bunch of vectors in a >> "method strictly for initialization" when it first starts running? If this >> cannot be done, then I guess the only solution is to initialize them in the >> work() method even though it would make the work() method bulky? >> >> Thanks again for your help. >> >> Regards, >> George >> >> On Wed, Jan 13, 2021 at 8:12 PM Jeff Long <willco...@gmail.com> wrote: >> >>> 'v' is a local variable in work(). It is probably crashing on the second >>> call, where my_init() is not called, and thus there is no 'v'. >>> >>> On Wed, Jan 13, 2021 at 7:38 PM George Edwards <gedwards....@gmail.com> >>> wrote: >>> >>>> Hello, >>>> >>>> I am using a Gnuradio Python Block in my GRC signal processing and am >>>> having problems initializing my parameters. My system has a number of >>>> vector parameters to be initialized at startup. I will provide the gist of >>>> my goal in a scaled down version of my work. >>>> 1. In the def __init__(self, start = True) method, "start" is the >>>> parameter that will be used in the program to run the initialization >>>> process and is set as follows: >>>> self.start = start >>>> 2. In the work(self, input_items, output_items) method, I have the >>>> following at the start of the method: >>>> if self.start == True: >>>> v = self.my_init() # go initialize all vectors >>>> >>>> output_items[0][:] = in0*v[0] + in1*v[1] + in2*v[2] >>>> #computation using v >>>> # with 3-inputs to >>>> the block >>>> >>>> 3. In the my_init(self) method I have: >>>> self.start = False # set start to False >>>> v = np.array([1., 2., 3.]) #hypothetical to make this simple >>>> return v >>>> >>>> When I run the GRC model, it tells me that "v" is referenced before >>>> assignment. I am confused because I thought that the method my_init() would >>>> have been called before the computation and would return the values for >>>> "v". On the other hand if I do the assignment in the work(...) method as v >>>> = np.array([1., 2., 3.]), it works perfectly. >>>> Question: Why was the my_init() method not called properly to get the >>>> values for the numpy array v? >>>> >>>> Thanks for the help! >>>> >>>> Regards, >>>> George >>>> >>>