Changing values of 1st column of a matrix using take(mymatrix, (0, ), axis=1)

Anthony Liu antonyliu2002 at yahoo.com
Mon Feb 20 23:17:30 EST 2006


Thanks, Tim, that is really cool.  I know there must
be some convenient way of doing this.



--- Tim Hochberg <tim.hochberg at ieee.org> wrote:

> Anthony Liu wrote:
> > I am talking about the 'take' method of numarray.
> > 
> > See here for more info:
> > 
> > http://stsdas.stsci.edu/numarray/Doc/node33.html
> > 
> > If I initialize a matrix 'mymatrix' by
> zeros((3,3),
> > type="Float64"), I get a 3*3 matrix of all zeros.
> > 
> > Look:
> > 
> > 
> >>>>from numarray import *
> >>>>mymatrix = zeros((3,3), type="Float64")
> >>>>mymatrix
> > 
> > array([[ 0.,  0.,  0.],
> >        [ 0.,  0.,  0.],
> >        [ 0.,  0.,  0.]])
> > 
> > 
> > I want to change the zeros of only the first
> column to
> > 1's.  In other words, I want to get:
> > 
> > array([[ 1.,  0.,  0.],
> >        [ 1.,  0.,  0.],
> >        [ 1.,  0.,  0.]])
> > 
> > The 'take' method is able to take out the first
> > column, but I am not sure if there is a good way
> of
> > changing all values of the first column to 1's.
> > 
> > Of course, I know that I can achieve my goal
> pretty
> > easily with this:
> > 
> > for i in range(3): mymatrix[i,0] = 1.0
> > 
> > I am just wondering if there is an existing
> numarray
> > method that elegantly does it for me.
> 
> mymatrix[:,0] = 1.0
> 
> > 
> > 
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam?  Yahoo! Mail has the best spam
> protection around 
> > http://mail.yahoo.com 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the Python-list mailing list