相关疑难解决方法(0)

用 numpy 旋转网格

我想生成一个坐标已旋转的网格。我必须在双循环中进行旋转,并且我确信有更好的方法来对其进行矢量化。代码如下:

# Define the range for x and y in the unrotated matrix
xspan = linspace(-2*pi, 2*pi, 101)
yspan = linspace(-2*pi, 2*pi, 101)

# Generate a meshgrid and rotate it by RotRad radians.
def DoRotation(xspan, yspan, RotRad=0):

    # Clockwise, 2D rotation matrix
    RotMatrix = np.array([  [np.cos(RotRad),  np.sin(RotRad)],
                            [-np.sin(RotRad), np.cos(RotRad)]])
    print RotMatrix

    # This makes two 2D arrays which are the x and y coordinates for each point.
    x, y = meshgrid(xspan,yspan)

    # After rotating, I'll have another two 2D arrays …
Run Code Online (Sandbox Code Playgroud)

python numpy rotation vectorization

6
推荐指数
2
解决办法
5369
查看次数

标签 统计

numpy ×1

python ×1

rotation ×1

vectorization ×1