gpt4 book ai didi

python - 使用 numpy.unique 获取数值数组中包含的每个唯一值的计数

转载 作者:行者123 更新时间:2023-11-30 22:15:25 30 4
gpt4 key购买 nike

给定一个 numpy 数组 a ,我可以使用 np.unique(a) 生成 a 中包含的唯一值。如何获取 a 中包含的每个唯一值的计数?

最佳答案

既然你提到np.unique ,它接受第二个名为 return_counts 的参数:

u, c = np.unique(a, return_counts=True)

c[i]u[i] 的相应计数。

关于python - 使用 numpy.unique 获取数值数组中包含的每个唯一值的计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50312134/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com