I want to initialize and fill a numpy array. What is the best way?
This works as I expect:
>>> import numpy as np
>>> np.empty(3)
array([ -1.28822975e-231,  -1.73060252e-077,   2.23946712e-314])
But this doesn't:
>>> np.empty(3).fill(np.nan)
>>> 
Nothing?
>>> type(np.empty(3))
<type 'numpy.ndarray'>
It seems to me that the np.empty() call is returning the correct type of object, so I don't understand why .fill() is not working? 
Assigning the result of np.empty() first works fine:
>>> a = np.empty(3)
>>> a.fill(np.nan)
>>> a
array([ nan,  nan,  nan])
Why do I need to assign to a variable in order to use np.fill()? Am I missing a better alternative?
 
     
     
     
     
     
    