简体   繁体   中英

how do i compute the average value of every n row of an array?

I have an array ( a ) and need to find the average of every 4th row.

Can I use np.mean to do this? I have tried this but it doesn't work:

means = np.mean(a, step=4, axis=1)
print(means)

You can do that with

means = np.mean(a[::4], axis=1)

Where a[::4] selects every 4th row from a.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM