Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #92930

Re: How to construct matrix from vectors?

From "Nasser M. Abbasi" <nma@12000.org>
Newsgroups comp.lang.python
Subject Re: How to construct matrix from vectors?
Date 2015-06-21 00:21 -0500
Organization Aioe.org NNTP Server
Message-ID <mm5hks$p52$1@speranza.aioe.org> (permalink)
References <mm55le$4sj$1@speranza.aioe.org> <mailman.665.1434853238.13271.python-list@python.org> <mm5c4c$fmm$1@speranza.aioe.org>

Show all headers | View raw


On 6/20/2015 10:47 PM, Nasser M. Abbasi wrote:

> I did manage to find a way:
>
> ---------------------------------
> r1 =np.hstack([(v1,v2)]).T
> r2 =np.hstack([(v3,v4)]).T
> mat = np.vstack((r1,r2))
> -----------------------------
>
> Out[211]:
> array([[ 1,  4],
>          [ 2,  5],
>          [ 3,  6],
>          [ 7, 10],
>          [ 8, 11],
>          [ 9, 12]])
>
> But it is not as intuitive as with Matlab, where one can just write
>
> -------------------------------
>     v1=[1,2,3]'; v2=[4,5,6]';
>     v3=[7,8,9]'; v4=[10,11,12]';
>     m=[v1 v2;v3 v4]
> -------------------------------

Here is a way a little closer to Matlab's method: First
make all the vectors column vectors

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 :)

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How to construct matrix from vectors? "Nasser M. Abbasi" <nma@12000.org> - 2015-06-20 20:57 -0500
  Re: How to construct matrix from vectors? MRAB <python@mrabarnett.plus.com> - 2015-06-21 03:20 +0100
    Re: How to construct matrix from vectors? "Nasser M. Abbasi" <nma@12000.org> - 2015-06-20 22:47 -0500
      Re: How to construct matrix from vectors? "Nasser M. Abbasi" <nma@12000.org> - 2015-06-21 00:21 -0500
        Re: How to construct matrix from vectors? Fabien <fabien.maussion@gmail.com> - 2015-06-21 10:49 +0200
          Re: How to construct matrix from vectors? Dave Farrance <df@see.replyto.invalid> - 2015-06-21 12:49 +0100
      Re: How to construct matrix from vectors? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-06-21 09:32 +0100
      Re: How to construct matrix from vectors? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-06-21 11:12 -0400
        Re: How to construct matrix from vectors? lanuradha@gmail.com - 2015-06-21 09:00 -0700
  Re: How to construct matrix from vectors? Tony the Tiger <tony@tiger.invalid> - 2015-07-09 20:23 +0000

csiph-web