[Numpy-discussion] take semantics (bug?)
robert.kern at gmail.com
Sun Dec 3 23:41:48 CST 2006
Michael McNeil Forbes wrote:
> What are the semantics of the "take" function?
> I would have expected that the following have the same shape and size:
>>>> a = array([1,2,3])
>>>> inds = a.nonzero()
> array([1, 2, 3])
> array([[1, 2, 3]])
> Is there a bug somewhere here or is this intentional?
It's a result of a.nonzero() returning a tuple.
In : a.nonzero()
Out: (array([0, 1, 2]),)
__getitem__ interprets tuples specially: a[1,2,3] == a[(1,2,3)], also a[0,] == a.
.take() doesn't; it simply tries to convert its argument into an array. It can
convert (array([0, 1, 2]),) into array([[0, 1, 2]]), so it does.
"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 Numpy-discussion