i创建一个存储类似信息的列表:
import numpy as np
moves = [(1, 2), (1, 3), (1, 4), (2, 1), (2, 3), (2, 4)]
wins = [i for i in range(2 * len(moves))]
playout_number = [23 for i in range(2 * len(moves))]
data = [list(map(lambda i: moves[i] if divmod(i, len(moves))[0] != 1 else moves[divmod(i, len(moves))[1]],
[i for i in range(2 * len(moves))])),
list(map(lambda i: 1 if i >= len(moves) else 2,
[i for i in range(2 * len(moves))])),
wins,
playout_number
]
table = np.asarray(data)
player1_info = table[:, np.where(table[1, :] == 1)[0].tolist()]
该代码效果很好,但是当我添加以下代码时:
b = np.divide(player1_info[2, :], player1_info[3, :]).reshape(1, player1.shape[1])
print(np.exp(b))
它发出错误:'float'对象没有属性'exp'。
如何重写代码以应对错误?
我像这样使用了 np.float64
:
b = np.divide(player1_info[2, :], player1_info[3, :])
b = np.float64(b)
print(np.exp(b))
感谢@Eric,我将table[:, np.where(table[1, :] == 1)[0].tolist()]
简单地更改为table[:, table[1, :] == 2]
。
错误没有显示出来,并给出了正确的答案。
我认为列表元素是np.exp
不知道的,并且无法计算。