Reputation: 12338
For example, if I have a NumPy array
import numpy as np
a = np.arange(10)
b = np.zeros(5)
How can I insert b
to the beginning of a
?
I know I can make a new array of size len(a)+len(b)
and do slice assignment, but is there a way to directly insert the array?
Upvotes: 1
Views: 4016
Reputation: 298096
You can use numpy.concatenate
:
>>> np.concatenate((b, a))
array([ 0., 0., 0., 0., 0., 0., 1., 2., 3., 4., 5., 6., 7.,
8., 9.])
Upvotes: 2