With numpy, say you have a vector like:
array([1, 2, 3])
How do you extend it n times with its own values? E.g.:
array([[1, 2, 3],
[1, 2, 3],
[1, 2, 3]])
CodePudding user response:
You can use numpy.tile
:
a = np.array([1, 2, 3])
N = 3
b = np.tile(a, (N,1))
or numpy.vstack
:
N = 3
b = np.vstack([a]*N)
output:
array([[1, 2, 3],
[1, 2, 3],
[1, 2, 3]])