【发布时间】:2021-08-05 10:56:18
【问题描述】:
假设我有一个值数组array = [0.0, 0.2, 0.5, 0.8, 1.0],我想将相邻的值配对到一个二级列表paired_array = [[0.0, 0.2], [0.2, 0.5], [0.5, 0.8], [0.8, 1.0]],在 numpy 中有没有简单的方法来做到这一点?
对于上下文,这些对表示概率范围,我将使用它来随机化字符串类型的 numpy 数组中的值。例如string_array = ['Fe', 'Pt', 'Fe', 'Pt', 'Fe', 'Pt', 'Fe', 'Pt'] 可能变成randomised_array = ['Pt', 'Fe', 'Pt', 'Pt', 'Pt', 'Pt', 'Fe', 'Fe']。在这种情况下,范围表示值是“Pt”或“Fe”的概率。
【问题讨论】:
标签: python arrays numpy random