python - 对 numpy 数组中的每一行应用函数?

标签 python arrays numpy

我正在尝试编写一个包含以下行的脚本,

fra = struct.frac_coords

“fra”给出以下答案:

array([[ 0.01106406,  0.11554355,  0.50754736],
   [ 0.00294858,  0.24640931,  0.99887037],
   [ 0.37046412,  0.08121749,  0.9386742 ],
   [ 0.49430774,  0.07065645,  0.7479905 ],
   [ 0.6249222 ,  0.04073112,  0.56187813]])

然后我有以下行:

periodic = struct.get_sites([ 0.01106406,  0.11554355,  0.50754736], 5.95, include_index=True)

print(periodic)

所以我必须将从“fra”获得的数组的每一行输入到“periodic”行中才能得到结果。如何以不需要将数组的行放入“周期性”命令的方式来制作行?

谢谢。

最佳答案

你很幸运!有一个很棒的东西叫做 for循环,让您依次循环每一行并计算相同的值。

fra = struct.frac_coords

for row in fra:
    periodic = struct.get_sites(row, 5.95, include_index=True) 
    print(periodic)

关于python - 对 numpy 数组中的每一行应用函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45666858/

相关文章:

python - 执行 K 均值聚类时出现的问题

python - 如何在我的预订系统中写入我的 CSV 文件 [STUCK]

python - Azure 中与 Aws SqS 最相似的队列服务是什么?

javascript - 如何从数组中找到 3 个数字的组合,添加后等于另一个给定数字

python - 将线性函数拟合到一组数据后,如何找到函数梯度上的​​误差?

python - Cython + OpenCV 和 NumPy

python - 在 macOS 中安装 virtualenvwrapper 时出现问题

python - 从该函数中确定函数名称(不使用回溯)

python - 有没有一种优雅的方法来检查数组中的哪些元素位于另一个容器中?

javascript - 复杂分组 : Array Reduce