Vpython 中的 Matlab 冒号运算符等效项

发布于 2024-12-03 02:22:12 字数 193 浏览 4 评论 0原文

在花了过去几个月学习 MATLAB 后,看来我需要切换到 vpython! MATLAB 的冒号运算符经常派上用场,但我在 vpython 中还没有找到等效的运算符。

作为参考,在 MATLAB 中:

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

有没有简单的方法可以在 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我爱人 2024-12-10 02:22:12

我不知道 vpython,但在仔细阅读其 教程 后,我猜想它与 Python 中相同

range(-3,4)
# [-3, -2, -1, 0, 1, 2, 3]

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]
撞了怀 2024-12-10 02:22:12

如果您使用 numpy,则可以使用 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])

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])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文