Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

np.intersect1d is several times faster for return_indices=True #16923

Copy link
Copy link
Open
@mganahl

Description

@mganahl
Issue body actions

For int16 arrays, intersect1d is faster for return_indices=True than for return_indices=False
by quite a margin (6x on my computer). Is this behavior preferred? I would expect the opposite.

Reproducing code example:

import numpy as np
import timeit
D=20000
a1 = np.random.randint(0,10,D, dtype=np.int16)
a2 = np.random.randint(0,10,D, dtype=np.int16)
print(timeit.timeit(lambda: np.intersect1d(a1, a2, return_indices=False), number=100))
print(timeit.timeit(lambda: np.intersect1d(a1, a2, return_indices=True), number=100))

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.