Fancy indexing is discussed in detail in
the Guide to NumPy.
http://www.tramy.us/guidetoscipy.html
Alan Isaac
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion
On 9-Aug-09, at 2:38 AM, T J wrote:
> Sure, but that wasn't my question.
>
> I was asking about the difference between indexing with a 1-tuple (or
> scalar) and with a 1-list. Naively, I guess I didn't expect there to
> be a difference. Though, I can see its uses (through the z[z<3]
> example).
On Sat, Aug 8, 2009 at 10:09 PM, David Warde-Farley wrote:
> On 9-Aug-09, at 12:36 AM, T J wrote:
>
> z = array([1,2,3,4])
> z[[1]]
>> array([1])
> z[(1,)]
>> 1
>>
> In the special case of scalar indices they're treated as if they are
> length-1 tuples. The behaviour you're seeing is th
On 9-Aug-09, at 12:36 AM, T J wrote:
z = array([1,2,3,4])
z[[1]]
> array([1])
z[(1,)]
> 1
>
> I'm just curious: What is the motivation for this differing behavior?
When you address, i.e. an element in 2D array with a[2,3] you are
actually indexing z with a tuple object (2,3). The
>>> z = array([1,2,3,4])
>>> z[[1]]
array([1])
>>> z[(1,)]
1
I'm just curious: What is the motivation for this differing behavior?
Is it a necessary consequence of, for example, the following:
>>> z[z<3]
array([1,2])
___
NumPy-Discussion mailing list
N