简体   繁体   English

如何扩展 numpy.ndarray

[英]How to extend a numpy.ndarray

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]) ,我在扩展 numpy.ndarry 时遇到了一些问题,有没有像列表的扩展()这样的方法?例如:给定两个数组, a=array([1,2,3]),b=array([4]) ,
want c=array([1,2,3,4])想要c=array([1,2,3,4])

or you can use hstack.或者你可以使用 hstack。 for example例如

a = np.array([1,2,3])
b = np.array([4])
c = np.hstack([a,b])

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.后者是最神秘的:它滥用方括号运算符以获得最紧凑的表示形式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM