简体   繁体   中英

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.

For instance, if I combine values, into a vector or list, in R like so:

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. 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?

in python, you could use numpy arrays to do such things

import numpy
x = numpy.array([2, 3, 7])
y = x*2 

and y will be equal to numpy.array([4, 6, 14])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM