I am on my transitional trip from MATLAB to scipy(+numpy)+matplotlib. I keep having issues when implementing some things. I want to create a simple vector array in three dif
if I understand the matlab correctly, you could accomplish something like this using:
a=np.array([0.2]+list(range(1,61))+[60.8])
But there's probably a better way...the list(range(1,61))
could just be range(1,61)
if you're using python 2.X.
This works by creating 3 lists and then concatenating them using the +
operator.
The reason your original attempt didn't work is because
a=[ [0.2], np.linspace(1,60,60), [60.8] ]
creates a list of lists -- in other words:
a[0] == [0.2] #another list (length 1)
a[1] == np.linspace(1,60,60) #an array (length 60)
a[2] == [60.8] #another list (length 1)
The array
function expects an iterable that is a sequence, or a sequence of sequences that are the same length.