python怎么新开一行_python中如何在矩阵中添加一列或是一行??

展开全部

>>> import numpy as np

>>> a = np.arange(1,11).reshape(10,1)

>>> b = a * 1.1

>>> c = a / 1.1

>>> a

array([[ 1],

[ 2],

[ 3],

[ 4],

[ 5],

[ 6],

[ 7],

[ 8],

[ 9],

[10]])

>>> b

array([[ 1.1],

[ 2.2],

[ 3.3],

[ 4.4],

[ 5.5],

[ 6.6],

[ 7.7],

[ 8.8],

[ 9.9],

[ 11. ]])

>>> c

array([[ 0.90909091],

[ 1.81818182],

[ 2.72727273],

[ 3.63636364],

[ 4.54545455],

[ 5.45454545],

[ 6.36363636],

[ 7.27272727],

[ 8.18181818],

[ 9.09090909]])

>>> x = np.array([

... np.reshape(a, len(a)),

... np.reshape(b, len(b)),

... np.reshape(c, len(c))

... ]).transpose()

>>> x

array([[ 1. , 1.1 , 0.90909091],

[ 2. , 2.2 , 1.81818182],

[ 3. , 3.3 , 2.72727273],

[ 4. , 4.4 , 3.63636364],

[ 5. , 5.5 , 4.54545455],

[ 6. , 6.6 , 5.45454545],

[ 7. , 7.7 , 6.36363636],

[ 8. , 8.8 , 7.27272727],

[ 9. , 9.9 , 8.18181818],

[ 10. , 11. , 9.09090909]])

>>>

is it?