pythonnumpylinspace

Can I insert a '0' in `np.linspace`?


Suppose I have this equally spaced 'darray':

epslist = np.linspace(-0.1,0.1,12)

Is there a way I can 'insert' a '0' in this 'darray' with the 'ordered' position? By that, in this case, '0' should be added to the middle of epslist, instead of in the end. I don't really know how to do that and which tools I could use. Thanks for the help!!


Solution

  • Use advanced indexing and concatenation for example:

    epslist = np.concatenate((epslist[epslist<0], [0], epslist[epslist>0]))