python Numpy 图像 - 将矩阵旋转 270 度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2461303/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Numpy image - rotate matrix 270 degrees
提问by Mikesname
I've got a Numpy 2d array that represents a grey-scale image and I need to rotate it 270 degrees. Might be being a bit thick here but the two ways I can find to do this seem quite... circulous:
我有一个代表灰度图像的 Numpy 2d 数组,我需要将它旋转 270 度。这里可能有点厚,但我能找到的两种方法似乎很......循环:
rotated = numpy.rot90(numpy.rot90(numpy.rot90(orignumpyarray)))
rotated = numpy.fliplr(numpy.flipud(numpy.rot90(orignumpyarray)))
I'm thinking there must be a better way to do this in one operation. Basically a rot270() function? Any ideas?
我认为必须有更好的方法在一次操作中做到这一点。基本上是一个 rot270() 函数?有任何想法吗?
回答by Anders Lindahl
You can tell rot90
to rotate several times, this should work:
你可以告诉rot90
给旋转几次,这应该工作:
rotated = numpy.rot90(orignumpyarray,3)
回答by Krunal Degamdiya
rotated_array =numpy.rot90(orignumpyarray,3)
Explanation of the function:
功能说明:
numpy.rot90(a,b)
a =Array which you want to rotate
b =How many times you want to rotate it by 90 degrees. For here you want 270° so
90° * 3 = 270° that is why b = 3 here.
numpy.rot90(a,b)
a =要旋转的数组
b =要旋转 90 度的次数。因为这里你想要 270° 所以 90° * 3 = 270° 这就是为什么这里 b = 3。