In MATLAB I can create monotonically spaced vectors as in the examples below using the :
, colon, operator. How can I do this in Python in a similarly concise manner?
>> x=1:10
x =
1 2 3 4 5 6 7 8 9 10
or
>> x=0:2:10
x =
0 2 4 6 8 10
@karakfa is right in that this is the way to create a simple list.
Matlab's vectors and matrices offer vectorised computation, though, and if that's what you need, you should probably use numpy.array
:
>>> import numpy
>>> numpy.arange(1, 11)
array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
there is range
range([start], stop[, step])
[]
shows optional arguments. Default ranges starts with zero
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With