相当于MATLAB冒号运算符的Python [英] Python Equivalent of MATLAB's colon operator

查看:189
本文介绍了相当于MATLAB冒号运算符的Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MATLAB中,可以使用:,冒号,运算符创建单调间隔的向量,如以下示例中所示.如何在Python中以类似的简洁方式做到这一点?

In MATLAB I can create monotonically spaced vectors as in the examples below using the :, colon, operator. How can I do this in Python in a similarly concise manner?

>> x=1:10
x =
     1     2     3     4     5     6     7     8     9    10

>> x=0:2:10
x =
     0     2     4     6     8    10

推荐答案

@karakfa是正确的,因为这是创建简单列表的方式.

@karakfa is right in that this is the way to create a simple list.

Matlab的向量和矩阵提供向量化的计算,如果这是您需要的,则可能应该使用numpy.array:

Matlab's vectors and matrices offer vectorised computation, though, and if that's what you need, you should probably use numpy.array:

>>> import numpy
>>> numpy.arange(1, 11)
array([ 1,  2,  3,  4,  5,  6,  7,  8,  9, 10])

这篇关于相当于MATLAB冒号运算符的Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆