在运行代码时出现这样的错误
unsupported operand type(s) for *: 'float' and 'NoneType'
如果我删除了这部分
Total = Total* exp
Total = 1-Total
possition = possition + 1
有这样的错误
IndexError: index 4 is out of bounds for axis 1 with size 4
代码:
import random
def getsys():
row = ''
for i in range(0 , 8):
randintt = str(random.randint(0 , 4))
row += randintt
return row
def getx():
x = []
for i in range(0,14):
mysys = getsys()
x.append(mysys)
return x
y = getx()
print (y)
import initialsys
import numpy as np
R = np.array([[0.90 , 0.93,0.91 , 0.95],
[0.95 , 0.94, 0.93, 0],
[0.85 , 0.90 , 0.87 , 0.92],
[0.83 , 0.87 , 0.85 , 0 ],
[0.94 , 0.93 , 0.95 , 0],
[0.99 , 0.98 , 0.97 , 0.96],
[0.91 , 0.92 , 0.94 , 0],
[0.81 , 0.90 , 0.91 , 0],
[0.97 , 0.99 , 0.96 , 0.91],
[0.83 , 0.85 , 0.90 , 0],
[0.94 , 0.95 , 0.96 , 0],
[0.79 , 0.82 , 0.85 , 0.90],
[0.98 , 0.99 , 0.97 , 0],
[0.85 , 0.92 , 0.95 , 0.99]
])
def expression(r ,possition , char ):
exp = 1-r[possition , int(char)]
x = initialsys.getx()
possition = 0
Total = 1
Total = float(Total)
char = ""
for row in x :
for char in row :
if char!= 0 :
exp = expression(R , possition , char)
Total = Total* exp
Total = 1-Total
possition = possition + 1
答案 0 :(得分:1)
您的函数def expression(r ,possition , char )
不返回任何内容。
您应该这样写:
def expression(r ,possition , char ):
return 1-r[possition , int(char)]
答案 1 :(得分:1)
变化的夫妇。
return
中的expression
语句random.randint(0 , 4)
应该是random.randint(0 , 3)
例如:
def expression(r ,possition , char ):
exp = 1-r[possition , int(char)]
return exp
def getsys():
row = ''
for i in range(0 , 8):
randintt = str(random.randint(0 , 3))
row += randintt
return row
答案 2 :(得分:0)
我将4更改为3,但IndexError:索引4超出了轴1的范围,尺寸4错误仍然存在