这是一个创建于 1884 天前的主题,其中的信息可能已经有所发展或是发生改变。
我想生成一串随机矩阵,用了 for 循环生成了 s0,s1,...sN 和 e0,e1,...,eN
然后想对其进行计算,使得 bi=si*ei,但是用 for 循环写不出来
B = np.random.randint(0,q,(m,n))
for i in range(0,N):
exec("s%s=np.random.randint(0,q,(n,1))"%i)
for i in range(0,N):
exec("e%s=np.random.randint(0,q,(m,1))"%i)
for i in range(0,N):
exec("b%s=np.dot(B,s%s)+e%s"%i)
我已经生成了 s0 到 sN 和 e0 到 eN 了,也可以 print,但是调用他们计算 bi 的时候会报错
exec("b%s=np.dot(B,s%s)+e%s"%i)
TypeError: not enough arguments for format string
3 条回复 • 2019-08-13 21:16:54 +08:00
|
|
1
cherbim 2019-08-13 20:56:52 +08:00
not enough arguments for format string 这个圈起来,期末考试要考,话说你知道这个报错啥意思么
|
|
|
2
cherbim 2019-08-13 21:02:45 +08:00
最后一行你要传递三个参数,虽然三个参数相同,那也不能省略
|
|
|
3
necomancer 2019-08-13 21:16:54 +08:00
B = np.random.randint(0,q,(m, n)) s = np.random.randint(0,q,(N, n)) e = np.random.randint(0,q,(N, m)) b = np.einsum('ij,...j->...i', B, s) + e
b -> (N, m)
|