gpt4 book ai didi

python - 如何对二维数组进行平均?

转载 作者:太空宇宙 更新时间:2023-11-04 08:14:07 25 4
gpt4 key购买 nike

我有一个形状为 (256,128) 的二维 numpy 数组,我想对 256 中的每 8 行进行平均,所以我最终得到一个形状为 ( 32,128) 有什么方法可以仅对一维进行平均吗?

最佳答案

您可以 reshape 然后在一个轴上平均:

 averaged = a.reshape((32,8,128)).mean(axis=1)

结果是一个 (32,128) 数组。

关于python - 如何对二维数组进行平均?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17575357/

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