Numpythonic方法:(使用numpy.dot获取两个矩阵的点积)
In [1]: import numpy as np
In [3]: np.dot([1,0,0,1,0,0], [[0,1],[1,1],[1,0],[1,0],[1,1],[0,1]])
Out[3]: array([1, 1])
Pythonic方法:
第二个for循环的长度是len(v),并且您尝试基于此索引v,因此您获得索引错误.作为一种更加pythonic的方式,您可以使用zip函数获取列表的列,然后在列表解析中使用starmap和mul:
In [13]: first,second=[1,0,0,1,0,0], [[0,1],[1,1],[1,0],[1,0],[1,1],[0,1]]
In [14]: from itertools import starmap
In [15]: from operator import mul
In [16]: [sum(starmap(mul, zip(first, col))) for col in zip(*second)]
Out[16]: [1, 1]