2

After spending the last few months learning about MATLAB, it seems I need to switch to vpython! MATLAB's colon operator comes in handy often and I haven't found an equivalent in vpython.

For reference, in MATLAB:

-3:3 = [-3, -2, -1, 0, 1, 2, 3]

Is there any easy way to do the same thing in vPython?

Alex Nichols
  • 876
  • 5
  • 12
  • 23

2 Answers2

2

I don't know vpython, but after perusing its tutorial, I would guess it is the same as in Python:

range(-3,4)
# [-3, -2, -1, 0, 1, 2, 3]
unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677
2

If you use numpy, you can use numpy.r_ :

>>> import numpy as np
>>> np.r_[-3:4]
array([-3, -2, -1,  0,  1,  2,  3])
>>> np.r_[-3:4, -5:7]
array([-3, -2, -1,  0,  1,  2,  3, -5, -4, -3, -2, -1,  0,  1,  2,  3,  4,
        5,  6])
HYRY
  • 94,853
  • 25
  • 187
  • 187