小编Mar*_*e_W的帖子

如何使numpy.argmax返回所有出现的最大值?

我正在尝试找到一个函数,它返回给定列表中所有出现的最大值.

numpy.argmax但是只返回它找到的第一个匹配项.例如:

from numpy import argmax

list = [7, 6, 5, 7, 6, 7, 6, 6, 6, 4, 5, 6]
winner = argmax(list)

print winner
Run Code Online (Sandbox Code Playgroud)

只给出索引0.但我希望它能给出所有指数:0, 3, 5.

python numpy max

45
推荐指数
3
解决办法
3万
查看次数

numpy 将数组追加到数组

我正在尝试将一个 numpy 数组附加到另​​一个 numpy 数组,如下所示:

import numpy as np
meanings = 2
signals = 4

def new_agent(agent_type, context_size):
    if agent_type == 'random':
        comm_system = np.random.random_integers(0, 1, (meanings, signals))
    if agent_type == 'blank':
        comm_system = np.zeros((meanings, signals), int)
    score_list = np.array([0., 0., 0., 0.])
    np.append(comm_system, score_list)
    np.append(comm_system, context_size)
    return comm_system
Run Code Online (Sandbox Code Playgroud)

如果我现在打电话:

random_agent = new_agent('random', 5)
Run Code Online (Sandbox Code Playgroud)

我希望得到类似的东西:

[[0 1 0 0]
[1 1 0 1]
[0. 0. 0. 0.]
5]
Run Code Online (Sandbox Code Playgroud)

但相反,我只得到:

[[0 1 0 0]
[1 1 0 1]]
Run Code Online (Sandbox Code Playgroud)

所以 score_list 和 …

python arrays numpy

1
推荐指数
1
解决办法
4357
查看次数

标签 统计

numpy ×2

python ×2

arrays ×1

max ×1