11 Vector

  • Generate a vector of numbers

11.1 R

Function Explanation Example.
: Generate a sequence of values x = 1:5; y = 7:9
seq Generate a sequence of values with specified start, stop and step z = seq(from = 2, to = 10, by = 2)
c Concatenate vectors x = 1:5; y = 7:9; z = c(x,y)
rep Generate repetitive values rep(1:5, times = 2); rep(1:3; each = 3)


11.2 Python

Function Explanation Example.
range Generate a sequence of values x = range(1, 6); y = range(2, 10, 2)
arange Generate a sequence of values with specified start, stop and step (import numpy as np) z = np.arange(2, 10, 2)
concatenate Concatenate vectors (import numpy as np) x = range(1,6); y = range(2, 10, 2); z = np.concatenate((x,y))
concatenate or repeat Generate repetitive values (import numpy as np) x = range(1, 5); w = numpy.concatenate((x, x, x)); z = np.repeat(x, 3, axis = 0)