【问题标题】:Matlab Colon Operator equivalent in VpythonVpython中等效的Matlab冒号运算符
【发布时间】:2011-09-05 20:52:11
【问题描述】:

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

供参考,在 MATLAB 中:

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

有没有简单的方法在 vPython 中做同样的事情?

【问题讨论】:

    标签: python matlab vpython


    【解决方案1】:

    我不知道vpython,但仔细阅读它的tutorial,我猜它是same as in Python

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

    【讨论】:

      【解决方案2】:

      如果你使用 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])
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-01-02
        • 1970-01-01
        • 1970-01-01
        • 2015-11-11
        • 1970-01-01
        • 2012-02-08
        相关资源
        最近更新 更多