Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #98940

Is there any reason to introduce this intermediate variable (sz)?

Newsgroups comp.lang.python
Date 2015-11-17 12:51 -0800
Message-ID <bad9ac66-38aa-4445-a486-6df0e9c7752c@googlegroups.com> (permalink)
Subject Is there any reason to introduce this intermediate variable (sz)?
From fl <rxjwg98@gmail.com>

Show all headers | View raw


Hi,

I find the following code snippet, which is useful in my project:


n_iter = 50
sz = (n_iter,) # size of array
x = -0.37727 
z = np.random.normal(x,0.1,size=sz) 

Q = 1e-5 # process variance

# allocate space for arrays
xhat=np.zeros(sz)      
P=np.zeros(sz)         


I learn Python now and the above code seems from an experienced author.
The curious thing to me is the variable 'sz'. I have check np.zeros(shape, ..)

shape : int or sequence of ints


The introduced 'sz' is a tuple. If n_iter function is similar to a constant
in C, I don't see the reason for 'sz'. In fact, 'n_iter' is an int, which fits
the below 

np.zeros(shape)

correctly. Could you see something useful with variable 'sz'?

Thanks,

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Is there any reason to introduce this intermediate variable (sz)? fl <rxjwg98@gmail.com> - 2015-11-17 12:51 -0800
  Re: Is there any reason to introduce this intermediate variable (sz)? John Gordon <gordon@panix.com> - 2015-11-17 21:02 +0000
    Re: Is there any reason to introduce this intermediate variable (sz)? fl <rxjwg98@gmail.com> - 2015-11-17 13:27 -0800
      Re: Is there any reason to introduce this intermediate variable (sz)? John Gordon <gordon@panix.com> - 2015-11-17 22:20 +0000
      Re: Is there any reason to introduce this intermediate variable (sz)? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-11-17 22:33 +0000
  Re: Is there any reason to introduce this intermediate variable (sz)? Dave Farrance <df@see.replyto.invalid> - 2015-11-18 08:05 +0000
  Re: Is there any reason to introduce this intermediate variable (sz)? Terry Reedy <tjreedy@udel.edu> - 2015-11-18 05:02 -0500

csiph-web