After spending the last few months learning about MATLAB, it seems I need to switch开发者_StackOverflow中文版 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?
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]
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])
精彩评论