[英]Python equivalent of R's c()?
This question has already been asked here: Python equivalent of R c() function , but unfortunately the solution given doesn't exactly apply to me.这里已经问过这个问题: Python相当于 R c() function ,但不幸的是给出的解决方案并不完全适用于我。
For instance, if I combine values, into a vector or list, in R like so:例如,如果我在 R 中将值组合成一个向量或列表,如下所示:
x = c(2,3,6,8)
I can preform calculations on that list, for example:我可以对该列表进行计算,例如:
x*2
Output:
4 6 12 16
However, I'm not sure how to achieve the same thing in Python.但是,我不确定如何在 Python 中实现相同的功能。 The previously asked question (in the link above) deals with a list of numbers in a particular range.先前提出的问题(在上面的链接中)涉及特定范围内的数字列表。 for example,例如,
x = list(range(1:10))
I am wondering, how do I define a list of numbers (not in a range) in Python?我想知道,如何在 Python 中定义数字列表(不在范围内)?
in python, you could use numpy arrays to do such things在 python 中,你可以使用 numpy 数组来做这样的事情
import numpy
x = numpy.array([2, 3, 7])
y = x*2
and y will be equal to numpy.array([4, 6, 14]) y 将等于 numpy.array([4, 6, 14])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.