展开全部
# Python3.6
import numpy as np
while True:
x = input("输入一62616964757a686964616fe78988e69d8331333431346435个m维数组,元素以空格分开:")
try:
# split input
x = x.split()
s = []
# iterate:str-->int
for i in x:
s.append(int(i))
x = s
break
except:
print("输入有错,请重新输入。")
while True:
n = input("整数n:")
try:
n = int(n)
break
except:
print("输入有错,请重新输入。")
# map object -->list object
lst = [i for i in x]
# list object -->numpy.array object
mtrx = np.array(lst)
# copy the 1st line of matrix as a template
mtrx_1 = np.copy(mtrx)
k = len(mtrx)
# reshape (k,) to (1,k) for concatenate
mtrx = np.reshape(mtrx, (1, k))
# calculate left lines
for i in range(1, n):
tmp = np.power(mtrx_1, i+1)
tmp = np.reshape(tmp, (1, k))
mtrx = np.concatenate((mtrx, tmp), axis=0)
print(mtrx)