本帖最后由 笨鸟学飞 于 2020-11-12 13:41 编辑
numpy.append(arr,values,axis=None)
arr : array_like
Values are appended to a copy of this array.
values : array_like
These values are appended to a copy of "arr". It must be of the correct shape (the same shape as "arr", excluding "axis"). If "axis" is not specified, "values" can be any shape and will be flattened before use.
这些值附加到"arr"的副本上。 它必须是正确的形状(与"arr"形状相同,不包括"轴")。 如果未指定"axis",则"values"可以是任何形状,并在使用前展平。
“与"arr"形状相同,不包括"轴"”,这句话的意思是说,一个数组两维,如果axis=0,则axis=1这一维形状要相同
=====================import numpy as np
DYX = np.zeros((3,1))
HXH = np.ones((3,8))
XH = np.append(DYX, HXH,axis=1)
print(DYX) #(3,1)
"""
[[0.]
[0.]
[0.]]
"""
print(HXH) # (3,8)
"""
[[1. 1. 1. 1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1. 1. 1. 1.]]
"""
#最终结果:
print(XH)
"""
[[0. 1. 1. 1. 1. 1. 1. 1. 1.]
[0. 1. 1. 1. 1. 1. 1. 1. 1.]
[0. 1. 1. 1. 1. 1. 1. 1. 1.]]
"""
print(XH.shape) #(3, 9)
#axis = 1,在第二维上拼接,所以说,(3,1)和(3,8)就变成了(3,9)
|