Reputation: 93
I have run into some problems to extend numpy.ndarry,Is there some ways like the list's extend()?for example:given two arrays ,a=array([1,2,3]),b=array([4])
,
want c=array([1,2,3,4])
Upvotes: 6
Views: 23651
Reputation: 33994
There're three equivalent ways:
np.concatenate((a,b))
np.hstack((a,b))
np.r_[a,b]
The latter being most cryptic: it abuses the square brackets operator in order to get the most compact representation form.
Upvotes: 2
Reputation: 1111
or you can use hstack. for example
a = np.array([1,2,3])
b = np.array([4])
c = np.hstack([a,b])
Upvotes: 9