[Numpy-discussion] finding index in an array...
Sat Jun 13 05:37:00 CDT 2009
On Sat, Jun 13, 2009 at 5:51 AM, fred<firstname.lastname@example.org> wrote:
> Emmanuelle Gouillart a écrit :
>> Hi Fred,
> Hi Manue ;-)
>> here is another solution
>>>>> A = np.arange(99).reshape((33,3)
>>>>> mask = (A==np.array([0,1,2]))
>>>>> np.nonzero(np.prod(mask, axis=1))
>> I found it to be less elegant than Josef's solution changing the dtype of
>> the array, but it may be easier to understand if you're not very familiar
>> with dtypes.
> I have no problem.
I think using a view instead of broadcasting in this case is
unnecessarily complicated. Maybe I was practicing views with
structured types too much.
using "all" instead of "prod" may be more descriptive:
>>> (A == np.array([1,2,3])).all(1).nonzero()
>>> (A == [1,2,3]).all(1).nonzero()
>> Also, it is a bit faster on my computer:
> I take it.
> Numpy-discussion mailing list
More information about the Numpy-discussion