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

C

Christian Seberino

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
 
R

Russell E. Owen

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
 
C

Christian Seberino

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:
array([[ 0, 1, 2, 3, 4, 5],
[ 6, 7, 8, 9, 10, 11],
[12, 13, 14, 15, 16, 17]])
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]])
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
 
D

David M. Cooke

At said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top