我有这个密码:
portes = [[0, 1, 2]] * 20
bonnes_portes = np.random.choice(range(3), size=(1, 20))
premier_choix = np.random.choice(range(3), size=(1, 20))
print(portes)
print(premier_choix)
这将输出:
[[0, 1, 2], [0, 1, 2], [0, 1, 2], [0, 1, 2], [0, 1, 2], [0, 1, 2], [0, 1, 2], [0, 1, 2], [0, 1, 2], [0, 1, 2], [0, 1, 2], [0, 1, 2], [0, 1, 2], [0, 1, 2], [0, 1, 2], [0, 1, 2], [0, 1, 2], [0, 1, 2], [0, 1, 2], [0, 1, 2]]
[[1 1 1 2 2 1 1 2 2 1 0 0 1 2 0 0 1 2 1 2]]
我想按顺序从portes
列表中删除premier_choix
列表的每个元素(从portes[0][0]
中删除premier_choix[0][0]
…,而不使用for循环。你知道吗
我假设总有一个元素要删除(就像上面的例子)。输入:
矢量化解决方案:
您可以使用
.remove()
完全删除列表可以使用
np.argwhere
参数获取相关索引,然后对数组执行切片操作,并将其重塑为所需的形式。你知道吗(示例-)输入
输出
相关问题 更多 >
编程相关推荐