Alex Nichols
Alex Nichols

Reputation: 896

Matlab Colon Operator equivalent in Vpython

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?

Upvotes: 2

Views: 1441

Answers (2)

HYRY
HYRY

Reputation: 97331

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])

Upvotes: 2

unutbu
unutbu

Reputation: 880449

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]

Upvotes: 2

Related Questions