How to construct matrix from vectors?
Fabien
fabien.maussion at gmail.com
Sun Jun 21 04:49:14 EDT 2015
On 06/21/2015 07:21 AM, Nasser M. Abbasi wrote:
> v1=np.array([(1,2,3)]).T
> v2=np.array([(4,5,6)]).T
> v3=np.array([(7,8,9)]).T
> v4=np.array([(10,11,12)]).T
>
> mat =np.hstack(( np.vstack((v1,v3)), np.vstack((v2,v4))) )
>
> Out[236]:
> array([[ 1, 4],
> [ 2, 5],
> [ 3, 6],
> [ 7, 10],
> [ 8, 11],
> [ 9, 12]])
>
> There are way too many '(([[]]))' things in Python :)
another solution with less "(([[]]))", and less ";". There are way too
many ";" in Matlab ;)
import numpy as np
v1 = [1, 2, 3]
v2 = [4, 5, 6]
v3 = [7, 8, 9]
v4 = [10, 11, 12]
np.hstack([[v1, v2], [v3, v4]]).T
Out[]:
array([[ 1, 4],
[ 2, 5],
[ 3, 6],
[ 7, 10],
[ 8, 11],
[ 9, 12]])
More information about the Python-list
mailing list