>>>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]])
>>>
使用numpy创建矩阵有2种方法,一种是使用numpy库的matrix直接创建,另一种则是使用array来创建。首先导入numpy:
(1)import numpy
(2)from numpy import *
(3)import numpy as np
相关推荐:《Python基础教程》
然后分别用上面说的2种方法来分别构建一个4×3的矩阵,如图:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)