From 2 Numpy vectors(length=m,n) , create crossed matrix(shape=(m, n,2))

As a reminder for MYSELF,

To create a matrix from two 1D vectors, like

v1 = np.arange(4)           #[0,1,2,3]
v2 = np.arange(4) *10    #[0,10,20,30]

to create crossed matrix

I do
crossed = np.dstack(( np.zeros((len(v1),len(v2)), dtype=v1.dtype) + v1[...,np.newaxis], 
                                    np.zeros((len(v1),len(v2)),dtype=v2.dtype) + v2))
Is there any better way to do it? Any suggestion will be appreciated.


Popular posts from this blog

Subclassing and Signal connect on a same widget crashes PySide application on exit.

Calling OpenCV functions via Cython from Python 3.X.

Showing CPU/Memory usage on tmux status bar(tmuxのステータスバーにCPUとMemoryの使用状況を表示する)