python - 如何在 numpy 中进行分散和聚集操作?

标签 python numpy indexing tensorflow pytorch

我想在 Numpy 中实现 Tensorflow 或 PyTorch 的分散和收集操作。我已经挠头好一阵子了。非常感谢任何指点!

最佳答案

有两个内置的 numpy 函数可以满足您的要求。

您可以使用 np.take_along_axis实现 torch.gather,并使用 np.put_along_axis实现 torch.scatter

关于python - 如何在 numpy 中进行分散和聚集操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46065873/

相关文章:

oracle - 与 Oracle 相比,在 Hadoop 中的表上使用索引有什么优势吗?

python - 如何在python中将多个netcdf文件合并为一个数据文件

python - 如何通过匹配字符串在Python中提取父html标签

python - 根据第一个数组删除第二个数组的索引位置

python - 访问数组 Python 中的元素

mysql - 索引的 DO 和 DONT

sql - 使用 ts_vector 列进行文本搜索

python - Tornado celery 集成黑客

Python 没有正确计算方程

python - 使用更重要的最近观察值计算平均值