numpy array creating with a sequence

You could try something like:

a = np.hstack(([0.2],np.linspace(1,60,60),[60.8]))

Does arange(0.2,60.8,0.2) do what you want?

http://docs.scipy.org/doc/numpy/reference/generated/numpy.arange.html


np.concatenate([[.2], linspace(1,60,60), [60.8]])

Well NumPy implements MATLAB's array-creation function, vector, using two functions instead of one--each implicitly specifies a particular axis along which concatenation ought to occur. These functions are:

  • r_ (row-wise concatenation) and

  • c_ (column-wise)


So for your example, the NumPy equivalent is:

>>> import numpy as NP

>>> v = NP.r_[.2, 1:10, 60.8]

>>> print(v)
     [  0.2   1.    2.    3.    4.    5.    6.    7.    8.    9.   60.8]

The column-wise counterpart is:

>>> NP.c_[.2, 1:10, 60.8]

slice notation works as expected [start:stop:step]:

>>> v = NP.r_[.2, 1:25:7, 60.8]

>>> v
  array([  0.2,   1. ,   8. ,  15. ,  22. ,  60.8])

Though if an imaginary number of used as the third argument, the slicing notation behaves like linspace:

>>> v = NP.r_[.2, 1:25:7j, 60.8]

>>> v
  array([  0.2,   1. ,   5. ,   9. ,  13. ,  17. ,  21. ,  25. ,  60.8])


Otherwise, it behaves like arange:

>>> v = NP.r_[.2, 1:25:7, 60.8]

>>> v
  array([  0.2,   1. ,   8. ,  15. ,  22. ,  60.8])