[Numpy-discussion] Functions for indexing into certain parts of an array (2d)
Fernando Perez
fperez.net@gmail....
Mon Jun 8 02:21:43 CDT 2009
On Sun, Jun 7, 2009 at 6:19 AM, Bruce Southey<bsouthey@gmail.com> wrote:
> On Sun, Jun 7, 2009 at 3:37 AM, Fernando Perez<fperez.net@gmail.com> wrote:
>> One more question. For these *_indices() functions, would you want an
>> interface that accepts *either*
>>
>> diag_indices(size,ndim)
>
> As I indicated above, this is unacceptable for the apparent usage.
Relax, nobody is trying to sneak past the Committee for the Prevention
of Unacceptable Things.
It's all now in a patch attached to this ticket:
http://projects.scipy.org/numpy/ticket/1132
for regular review. I added the functions, with docstrings and tests.
By the way, despite being above indicated as unacceptable, I still see
value in being able to create these indexing structures without an
actual array, so the implementation contains both versions, but with
different names (to avoid the shenanigans that Robert rightfully has
a policy of avoiding).
> I do not understand what is expected with the ndim argument. If it is
> the indices of an array elements of the form: [0][0][0], [1][1][1],
> ... [k][k][k] where k=min(a.shape) for some array a then an ndim args
> is total redundant (although using shape is not correct for 1-d
> arrays). This is different than the diagonals of two 2-d arrays from
> an shape of 2 by 3 by 4 or some other expectation.
For an n-dimensional array, which probably comes closest to what we
think of as a tensor in (muti) linear algebra, the notion of a
diagonal as the list of entries with indices A[i,i,i,....,i] for i in
[0...N] is a very natural one.
>> diag_indices(anarray)
>>
>
> +1
These were also added in this form, with the name _from(A), indicating
that size/shape information should be taken from the input A. So both
versions exist.
Feel free to provide further feedback on the patch.
Cheers,
f
More information about the Numpy-discussion
mailing list