测试错误–不知道为啥,未深究!!!
def F(q,M):
S=M[q-1,0]*2+M[q-1,1]*3
#S=np.floor(1/q)
return S
M=np.array([[4,2,1,2],
[2,4,2,1],
[1,2,4,2],
[2,1,2,4]])
VF=np.vectorize(F)
print(VF([1,2,3,4],M))
测试正确-巧借对象来处理
import numpy as np
def F(q,T):
M=T.M
S=M[q-1,0]*2+M[q-1,1]*3
#S=np.floor(1/q)
return S
M=np.array([[4,2,1,2],
[2,4,2,1],
[1,2,4,2],
[2,1,2,4]])
VF=np.vectorize(F)
class FF():
def __init__(self,M):
self.__M=M
@property
def M(self):
return self.__M
T=FF(M)
print(VF([1,2,3,4],T))
#[14 16 8 7]