本文介绍了反转ndarray中的任意维的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用n维数组,我想一种反转编号维的方法.所以,而不是

I'm working with an n-dimensional array, and I'd like a way to reverse a numbered dimension. So rather than

rev = a[:,:,::-1]

我想写

rev = a.reverse(dimension=2)

或类似的东西.我似乎找不到不依赖以前语法的示例.

or something similar. I can't seem to find examples that don't rely on the former syntax.

推荐答案

对于以后遇到此问题的任何人:

For anyone coming across this in the future:

Numpy 1.12+具有功能 np.flip(array, dimension) ,完全按照要求执行.更好的是,它返回的是数据视图而不是副本,因此它发生的时间是恒定的.

Numpy 1.12+ has the function np.flip(array, dimension), which does exactly as requested. Even better, it returns a view of the data rather than a copy, and so it happens in constant time.

这篇关于反转ndarray中的任意维的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 21:18