[SciPy-user] assign to diagonal values?

Robert Kern robert.kern@gmail....
Wed Jul 1 13:38:49 CDT 2009


On Wed, Jul 1, 2009 at 12:21, Scott David Daniels<Scott.Daniels@acm.org> wrote:
> Robert Kern wrote:
>> On Sat, May 23, 2009 at 16:26, Alan G Isaac <aisaac@american.edu> wrote:
>>>> On Sat, May 23, 2009 at 16:02, Alan G Isaac wrote:
>>>>> On 1/31/2008 1:37 AM Anne Archibald apparently wrote:
>>>>>> m[range(n),range(n)]=new_diagonal
>>>>> Will that work with range objects (in Python 3)?
>>> On 5/23/2009 5:05 PM Robert Kern apparently wrote:
>>>> No. The automatic conversion to arrays does not consume iterators (nor
>>>> will it when we port to Python 3).
>>> Sure, but range objects are not iterators.
>>> They are "almost" sequences.
>>
>> The answer is still no. Perhaps someone will write special support for
>> that type when we do the Python 3 port, but there's nothing in numpy
>> that would make it work automatically. For example, xrange() does not
>> work as an index with the current numpy.
>
> Well, ranges are more capable than you think in Python 3:
>     v = range(25)
>     print (v[3], v[0], v[22], v)
> prints:
>     3 0 22 range(0, 25)

No, they are exactly as capable as I think, i.e. as capable as
xrange() is in Python 2:

  In [10]: v = xrange(25)

  In [11]: print v[3], v[0], v[22], v
  3 0 22 xrange(25)

Quite simply, numpy does not support arbitrary sequences and
sequence-like objects as indices. If the eventual numpy port to Python
3 supports range() objects as indices, it will be because someone will
have written special code for it.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco


More information about the SciPy-user mailing list