我尝试过使用for循环来生成列表数组中的每一列,这行得通。但是不幸的是,我不能在np.append(matrix_name,values(= list),axis = 0)comand中使用此列表,并将这些值作为列添加到大小为10x10的已定义矩阵X中。
答案 0 :(得分:0)
这应该做
np.tile(np.arange(1, 11), (10, 1)).cumprod(axis=0)
让我们看看我们正在做什么。
生成第一行
np.arange(1, 11)
array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
重复十次
np.tile(np.arange(1, 11), (10, 1))
array([[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]])
将每行乘以沿轴0的上一行
np.tile(np.arange(1, 11), (10, 1)).cumprod(axis=0)
array([[ 1, 2, 3, 4, 5,
6, 7, 8, 9, 10],
[ 1, 4, 9, 16, 25,
36, 49, 64, 81, 100],
[ 1, 8, 27, 64, 125,
216, 343, 512, 729, 1000],
[ 1, 16, 81, 256, 625,
1296, 2401, 4096, 6561, 10000],
[ 1, 32, 243, 1024, 3125,
7776, 16807, 32768, 59049, 100000],
[ 1, 64, 729, 4096, 15625,
46656, 117649, 262144, 531441, 1000000],
[ 1, 128, 2187, 16384, 78125,
279936, 823543, 2097152, 4782969, 10000000],
[ 1, 256, 6561, 65536, 390625,
1679616, 5764801, 16777216, 43046721, 100000000],
[ 1, 512, 19683, 262144, 1953125,
10077696, 40353607, 134217728, 387420489, 1000000000],
[ 1, 1024, 59049, 1048576, 9765625,
60466176, 282475249, 1073741824, 3486784401, 10000000000]])