Adding values to sequentially spaced list in python? -


i new python , confused how represent following code matlab python:

p = [2:35,50,100,200] 

in matlab, spit out: p = [2,3,...,35,50,100,200] ; however, can't seem figure out how add values list sequential numbering done in matlab. suggestions great. thanks!

vanilla python doesn't have dedicated syntax ... if you're working lists, need 2 steps:

lst = list(range(2, 36))  # python2.x, don't need `list(...)` lst.extend([50, 100, 200]) 

if have "bleeding edge" (python3.5), you can use unpacking:

lst = [*range(2, 36), 50, 100, 200] 

if you're using numpy, can use r_ index trick (which looks similar matlab version):

>>> import numpy np >>> np.r_[2:36, 100, 200, 500] array([  2,   3,   4,   5,   6,   7,   8,   9,  10,  11,  12,  13,  14,     15,  16,  17,  18,  19,  20,  21,  22,  23,  24,  25,  26,  27,     28,  29,  30,  31,  32,  33,  34,  35, 100, 200, 500]) 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -