Re: [Numpy-discussion] Matrices and arrays of vectors

2012-02-24 Thread Pierre Haessig
Le 24/02/2012 14:49, Bob Dowling a écrit : > Thank you all (and especially the gentleman who spotted I was rotating > in the wrong direction). No I hadn't ! I had just mentioned the transpose issue for writing "numpy.dot(data,rotation)". So in the end the two sign flips cancel each other and Nicol

Re: [Numpy-discussion] Matrices and arrays of vectors

2012-02-24 Thread Bob Dowling
numpy.dot and numpy.tensordot do exactly what I need. Thank you all (and especially the gentleman who spotted I was rotating in the wrong direction). ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/nu

Re: [Numpy-discussion] Matrices and arrays of vectors

2012-02-24 Thread gary ruben
I haven't checked correctness, but how about np.tensordot(rotation, data, axes=1) Gary R On 24 February 2012 23:11, Bob Dowling wrote: > Conceptually, I have a 2-d grid of 2-d vectors.  I am representing this > as an ndarray of shape (2,M,N).  I want to apply a 2x2 matrix > individually to each

Re: [Numpy-discussion] Matrices and arrays of vectors

2012-02-24 Thread Pierre Haessig
Hi, Le 24/02/2012 13:55, Nicolas Rougier a écrit : > You should use a (M,N,2) array to store your vectors: > [...] > [...] > numpy.dot(data,rotation) looking at how numpy.dot generalizes the matrix product* to N-dim arrays, I came to the same conclusion. I just suspect that the 'rotation' array sh

Re: [Numpy-discussion] Matrices and arrays of vectors

2012-02-24 Thread Nicolas Rougier
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],

[Numpy-discussion] Matrices and arrays of vectors

2012-02-24 Thread Bob Dowling
Conceptually, I have a 2-d grid of 2-d vectors. I am representing this as an ndarray of shape (2,M,N). I want to apply a 2x2 matrix individually to each vector in the grid. However, I can't work out the appropriate syntax for getting the matrix multiplication to broadcast over the grid. All