# [SciPy-User] matrix of vectors

Marco gaedol@gmail....
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?

Thank you!

marco

On Tue, Dec 1, 2009 at 5:53 PM, Neil Martinsen-Burrell <nmb@wartburg.edu> 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")
>>>> a[0,0]
> 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[8]: a = np.zeros((N,N,3))
>
> In [9]: a[1,1]
> Out[9]: 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.
>
> -Neil
>
```