Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
例如,如果我有一个 NumPy 数组
import numpy as np a = np.arange(10) b = np.zeros(5)
如何插入b到开头a?
b
a
我知道我可以创建一个新的大小数组len(a)+len(b)并进行切片分配,但是有没有办法直接插入数组?
len(a)+len(b)
这个怎么样:
c = np.hstack([b, a])
您可以使用numpy.concatenate:
numpy.concatenate
>>> np.concatenate((b, a)) array([ 0., 0., 0., 0., 0., 0., 1., 2., 3., 4., 5., 6., 7., 8., 9.])