# [Numpy-discussion] Matrices and arrays of vectors

Nicolas Rougier Nicolas.Rougier@inria...
Fri Feb 24 06:55:41 CST 2012

```You should use a (M,N,2) array to store your vectors:

import math
import numpy
import numpy.random

# Rotation angle
theta = math.pi/6.0

# Grid shape
M = 10
N = 10

# Establish the rotation matrix
c = math.cos(theta)
s = math.sin(theta)
rotation = numpy.array([[c,      s],
[-1.0*s, c]])

# Fudge some data to work with
data = numpy.random.uniform(-1.0, 1.0, (M,N,2))

numpy.dot(data,rotation)

Nicolas

On Feb 24, 2012, at 13:11 , Bob Dowling wrote:

> import math
> import numpy
> import numpy.random
>
> # Rotation angle
> theta = math.pi/6.0
>
> # Grid shape
> M = 10
> N = 10
>
> # Establish the rotation matrix
> c = math.cos(theta)
> s = math.sin(theta)
> rotation = numpy.matrix([[c, s], [-1.0*s, c]])
>
> # Fudge some data to work with
> data = numpy.random.uniform(-1.0, 1.0, 2*M*N).reshape(2,M,N)
>
> # THIS DOES NOT WORK.
> # BUT WHAT DOES?
> rotated_data = rotation*data

```