2018-06-29 10:21:13 1632浏览
今天小编就为大家分享一篇对numpy.append()里的axis的用法详解,具有很好的参考价值,希望对大家有所帮助。让大家对Python更有兴趣.
defappend(arr,values,axis=None): """ Appendvaluestotheendofanarray. Parameters ---------- arr:array_like Valuesareappendedtoacopyofthisarray. values:array_like Thesevaluesareappendedtoacopyof`arr`.Itmustbeofthe correctshape(thesameshapeas`arr`,excluding`axis`).If `axis`isnotspecified,`values`canbeanyshapeandwillbe flattenedbeforeuse. axis:int,optional Theaxisalongwhich`values`areappended.If`axis`isnot given,both`arr`and`values`areflattenedbeforeuse. Returns ------- append:ndarray Acopyof`arr`with`values`appendedto`axis`.Notethat `append`doesnotoccurin-place:anewarrayisallocatedand filled.If`axis`isNone,`out`isaflattenedarray.
当axis无定义时,是横向加成,返回总是为一维数组。
Examples -------- >>>np.append([1,2,3],[[4,5,6],[7,8,9]]) array([1,2,3,4,5,6,7,8,9])
importnumpyasnp aa=np.zeros((1,8)) bb=np.ones((3,8)) c=np.append(aa,bb,axis=0) print(c) [[0.0.0.0.0.0.0.0.] [1.1.1.1.1.1.1.1.] [1.1.1.1.1.1.1.1.] [1.1.1.1.1.1.1.1.]
importnumpyasnp aa=np.zeros((3,8)) bb=np.ones((3,1)) c=np.append(aa,bb,axis=1) print(c) [[0.0.0.0.0.0.0.0.1.] [0.0.0.0.0.0.0.0.1.] [0.0.0.0.0.0.0.0.1.]]
以上这篇对numpy.append()里的axis的用法详解就是扣丁学堂分享给大家的全部内容了,希望能给大家一个参考,对大家有更大的帮助,要了解更多关于Python知识,请登录扣丁学堂官网,或者关注微信公众号了解更多,更有大量Python在线视频教程等着你!!!
【关注微信公众号获取更多学习资料】