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

Discussion in 'Python' started by Anthony Liu, Feb 21, 2006.

  1. Anthony Liu

    Anthony Liu Guest

    I am talking about the 'take' method of numarray.

    See here for more info:

    If I initialize a matrix 'mymatrix' by zeros((3,3),
    type="Float64"), I get a 3*3 matrix of all zeros.

    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.

    Do You Yahoo!?
    Tired of spam? Yahoo! Mail has the best spam protection around
    Anthony Liu, Feb 21, 2006
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.