这是我创建要添加的向量的“矩阵”的代码:
vectors_num = int(input("Enter number of vectors: "))
vectors_dim = int(input("Enter dimension of vectors: "))
vector_list = list()
for i in range (vectors_num):
print("Enter your vector:")
try:
tmp = list(map(int, input().split()))
if len(tmp) != vectors_dim:
raise ValueError ("Vector dimension must be the same")
vector_list.append(tmp)
except ValueError as e:
print(e)
我需要使用 map 函数和 lambda 函数在一行中添加矢量数据。例子:
vector_list = 1 2 3
4 5 6
7 8 9
result = 6
15
24
不使用 numpy 和其他第三方库。
在一行中: