[SciPy-User] matrix of vectors
Neil Martinsen-Burrell
nmb@wartburg....
Tue Dec 1 10:53:54 CST 2009
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
More information about the SciPy-User
mailing list