You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否优化这个基于numpy数组的原子索引生成函数?

多分子原子索引生成函数
  • 参数说明:
    • a:一维整数数组,代表第一个分子的原子索引
    • step:单个分子包含的原子数量
    • n:需要生成索引的分子总数

该函数用于将针对单个分子的原子选择逻辑,批量应用到n个相同分子上,生成所有分子对应的目标原子索引。

实现代码

import numpy as np

def f(a, step, n):
    a.shape=1,-1
    got = np.repeat(a, n, axis=0)
    blocks = np.arange(0, n*step, step)
    blocks.shape = n, -1
    return got + blocks

示例运行

In [52]: f(np.array([1,3,4]), 10, 4)
Out[52]:
array([[ 1,  3,  4],
       [11, 13, 14],
       [21, 23, 24],
       [31, 33, 34]])

内容的提问来源于stack exchange,提问作者nos

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 15:19:21