[SciPy-User] matrix of vectors
Tue Dec 1 10:56:42 CST 2009
Thank you Neil!
I guess I'll go with the first option.
I wasn't aware of the chance to use these tricks on scipy.
Any pointers to this kind of tricks?
On Tue, Dec 1, 2009 at 5:53 PM, Neil Martinsen-Burrell <email@example.com> wrote:
> On 2009-12-01 09:35 , Marco wrote:
>> Hi all,
>> I'd need to build a matrix (NxN) in which each element is a vector
>> with 3 components.
> One possible way to do this is to use a rich datatype like
>>>> N = 64
>>>> a = np.zeros((N,N), dtype=np.dtype("(3,)f8")
> array([ 0., 0., 0.])
> which defines an NxN array whose elements are length 3 vectors of floats.
> You can also just think of this as an NxNx3 array of floats where numpy's
> indexing rules let you index just the first two dimensions:
> In: a = np.zeros((N,N,3))
> In : a[1,1]
> Out: array([ 0., 0., 0.])
> You should note that if you want to multiply these vectors by other matrices
> (such as rotations, etc.) then it is possible (but tricky) to use np.dot to
> do so.
More information about the SciPy-User