On Sat, Jun 6, 2009 at 11:46 AM, Keith Goodman <kwgood...@gmail.com> wrote:
> On Sat, Jun 6, 2009 at 11:30 AM, Fernando Perez <fperez....@gmail.com> wrote:
>> On Sat, Jun 6, 2009 at 12:09 AM, Robert Kern<robert.k...@gmail.com> wrote:
>>> diag_indices() can be made more efficient, but these are fine.
>>
>> Suggestion?  Right now it's not obvious to me...
>
> I'm interested in a more efficient way too. Here's how I plan to adapt
> the code for my personal use:
>
> def fill_diag(arr, value):
>    if arr.ndim != 2:
>        raise ValueError, "Input must be 2-d."
>    idx = range(arr.shape[0])
>    arr[(idx,) * 2] = value
>    return arr

Maybe it is confusing to return the array since the operation is in place. So:

def fill_diag(arr, value):
    if arr.ndim != 2:
        raise ValueError, "Input must be 2-d."
    idx = range(arr.shape[0])
    arr[(idx,) * 2] = value
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to