Easiest way to *add a column* to a 2d matrix/array in numarray???

Discussion in 'Python' started by Christian Seberino, Apr 20, 2004.

  1. How add a column to a 2d array/matrix in numarray???

    The unelegant way I found was to:

    1. Create a new array with an extra column (e.g. using 'zeros' function).
    2. Copy original array into new array.
    3. Copy new column into last column.

    Is there a slicker way to do this?

    Chris
     
    Christian Seberino, Apr 20, 2004
    #1
    1. Advertising

  2. In article <>,
    (Christian Seberino) wrote:

    >How add a column to a 2d array/matrix in numarray???
    >
    >The unelegant way I found was to:
    >
    >1. Create a new array with an extra column (e.g. using 'zeros' function).
    >2. Copy original array into new array.
    >3. Copy new column into last column.
    >
    >Is there a slicker way to do this?


    Try numarray.resize

    -- Russell
     
    Russell E. Owen, Apr 21, 2004
    #2
    1. Advertising

  3. Thanks for the reply. I appreciate all the help I can get. Your suggestion
    of using resize is excellent for adding *rows* but does not seem
    right for *columns*. Here is an example:

    >>> a

    array([[ 0, 1, 2, 3, 4, 5],
    [ 6, 7, 8, 9, 10, 11],
    [12, 13, 14, 15, 16, 17]])

    >>> a.resize((4,6))
    >>> a

    array([[ 0, 1, 2, 3, 4, 5],
    [ 6, 7, 8, 9, 10, 11],
    [12, 13, 14, 15, 16, 17],
    [ 0, 1, 2, 3, 4, 5]])

    >>> a.resize((4,7))
    >>> a

    array([[ 0, 1, 2, 3, 4, 5, 6],
    [ 7, 8, 9, 10, 11, 12, 13],
    [14, 15, 16, 17, 0, 1, 2],
    [ 3, 4, 5, 0, 1, 2, 3]])

    Do you see how adding an extra row left old rows intact but
    adding an extra column messes up old columns? (i.e.
    data in (1,1) position is not the same after adding a column)

    Chris


    "Russell E. Owen" <> wrote in message news:<c66jij$nps$>...
    > In article <>,
    > (Christian Seberino) wrote:
    >
    > >How add a column to a 2d array/matrix in numarray???
    > >
    > >The unelegant way I found was to:
    > >
    > >1. Create a new array with an extra column (e.g. using 'zeros' function).
    > >2. Copy original array into new array.
    > >3. Copy new column into last column.
    > >
    > >Is there a slicker way to do this?

    >
    > Try numarray.resize
    >
    > -- Russell
     
    Christian Seberino, Apr 22, 2004
    #3
  4. Re: Easiest way to *add a column* to a 2d matrix/array innumarray???

    At some point, (Christian Seberino) wrote:

    > Thanks for the reply. I appreciate all the help I can get. Your suggestion
    > of using resize is excellent for adding *rows* but does not seem
    > right for *columns*.


    If rows works, you could do transpose/resize/transpose.

    --
    |>|\/|<
    /--------------------------------------------------------------------------\
    |David M. Cooke
    |cookedm(at)physics(dot)mcmaster(dot)ca
     
    David M. Cooke, Apr 23, 2004
    #4
  5. David

    Thanks. That was pretty clever methinks.

    Chris


    (David M. Cooke) wrote in message news:<>...
    > At some point, (Christian Seberino) wrote:
    >
    > > Thanks for the reply. I appreciate all the help I can get. Your suggestion
    > > of using resize is excellent for adding *rows* but does not seem
    > > right for *columns*.

    >
    > If rows works, you could do transpose/resize/transpose.
     
    Christian Seberino, Apr 27, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. lvcargnini

    Matrix composed by two matrix

    lvcargnini, Jul 4, 2006, in forum: VHDL
    Replies:
    3
    Views:
    2,688
    Jonathan Bromley
    Jul 5, 2006
  2. Christian Seberino
    Replies:
    5
    Views:
    1,059
    Skip Montanaro
    Feb 10, 2004
  3. Curzio Basso

    [numarray] mean vector of 2d matrix

    Curzio Basso, May 10, 2004, in forum: Python
    Replies:
    2
    Views:
    468
    Curzio Basso
    May 12, 2004
  4. =?Utf-8?B?cm9kY2hhcg==?=

    easiest way to add a trigger

    =?Utf-8?B?cm9kY2hhcg==?=, Oct 10, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    296
    =?Utf-8?B?cm9kY2hhcg==?=
    Oct 10, 2006
  5. Thriving K.
    Replies:
    2
    Views:
    211
    Gennady Bystritsky
    Aug 4, 2009
Loading...

Share This Page