Python - Y.shape[n,m];Numpy中的矩阵合并
2020-12-13 17:01
标签:shape dimens type nump res none post value ott The numpy.full(shape, fill_value, dtype = None, order = ‘C’) : Return a new array with the same shape and type as a given array filled with a fill_value. output: 列合并/扩展:np.column_stack() 行合并/扩展:np.row_stack() Python - Y.shape[n,m];Numpy中的矩阵合并 标签:shape dimens type nump res none post value ott 原文地址:https://www.cnblogs.com/Bella2017/p/11622636.htmlshape
attribute for numpy arrays returns the dimensions of the array. If Y
has n
rows and m
columns, then Y.shape
is (n,m)
. So Y.shape[0]
is n
.In [46]: Y = np.arange(12).reshape(3,4)
In [47]: Y
Out[47]:
array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]])
In [48]: Y.shape
Out[48]: (3, 4)
#行数
In [49]: Y.shape[0]
Out[49]: 3#列数
In [49]: Y.shape[1]
Out[49]: 4
# Python Programming illustrating
# numpy.full method
import numpy as np
a = np.full([2, 2], 67, dtype = int)
print("\nMatrix a : \n", a)
c = np.full([3, 3], 10.1)
print("\nMatrix c : \n", c)
Matrix a :
[[67 67]
[67 67]]
Matrix c :
[[ 10.1 10.1 10.1]
[ 10.1 10.1 10.1]
[ 10.1 10.1 10.1]]
Numpy中的矩阵合并
>>> import numpy as np
>>> a = np.arange(9).reshape(3,-1)
>>> a
array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
>>> b = np.arange(10, 19).reshape(3, -1)
>>> b
array([[10, 11, 12],
[13, 14, 15],
[16, 17, 18]])
>>> top = np.column_stack((a, np.zeros((3,3))))
>>> top
array([[ 0., 1., 2., 0., 0., 0.],
[ 3., 4., 5., 0., 0., 0.],
[ 6., 7., 8., 0., 0., 0.]])
>>> bottom = np.column_stack((np.zeros((3,3)), b))
>>> bottom
array([[ 0., 0., 0., 10., 11., 12.],
[ 0., 0., 0., 13., 14., 15.],
[ 0., 0., 0., 16., 17., 18.]])
>>> np.row_stack((top, bottom))
array([[ 0., 1., 2., 0., 0., 0.],
[ 3., 4., 5., 0., 0., 0.],
[ 6., 7., 8., 0., 0., 0.],
[ 0., 0., 0., 10., 11., 12.],
[ 0., 0., 0., 13., 14., 15.],
[ 0., 0., 0., 16., 17., 18.]])
文章标题:Python - Y.shape[n,m];Numpy中的矩阵合并
文章链接:http://soscw.com/essay/36683.html