NumPy 2.4: module 'numpy' has no attribute 'in1d' / 'trapz' (tested)

AttributeError: module 'numpy' has no attribute 'in1d' (or 'trapz') means NumPy 2.4 or newer: both were deprecated in 2.0 and removed in 2.4. Use np.isin and np.trapezoid. Tested below.

1. Same script on NumPy 2.3 and NumPy 2.4

import warnings
warnings.simplefilter("always")
import numpy as np
print("numpy", np.__version__)
a = np.array([1, 2, 3, 4])
for name, call in [("in1d", lambda: np.in1d(a, [2, 4])),
                   ("trapz", lambda: np.trapz([1, 2, 3]))]:
    try:
        print(name, "->", call())
    except AttributeError as e:
        print(name, "-> AttributeError:", e)
print("isin ->", np.isin(a, [2, 4]))
print("trapezoid ->", np.trapezoid([1, 2, 3]))

NumPy 2.3.5: both work, with a DeprecationWarning naming the replacement:

numpy 2.3.5
b1.py:6: DeprecationWarning: `in1d` is deprecated. Use `np.isin` instead.
  for name, call in [("in1d", lambda: np.in1d(a, [2, 4])),
in1d -> [False  True False  True]
b1.py:7: DeprecationWarning: `trapz` is deprecated. Use `trapezoid` instead, or one of the numerical integration functions in `scipy.integrate`.
  ("trapz", lambda: np.trapz([1, 2, 3]))]:
trapz -> 4.0
isin -> [False  True False  True]
trapezoid -> 4.0

NumPy 2.4.6: both are gone, and the error gives no hint:

numpy 2.4.6
in1d -> AttributeError: module 'numpy' has no attribute 'in1d'
trapz -> AttributeError: module 'numpy' has no attribute 'trapz'
isin -> [False  True False  True]
trapezoid -> 4.0

2. Replacements

If the call is inside a library (the traceback ends in site-packages), upgrade that library or pin numpy<2.4. Example: astropy 6.1 to 7.1 fail at from astropy import units on NumPy 2.4; 7.2.0 works (tested). In the same NumPy 2.4.6 install, np.product, np.cumproduct and np.msort also raised plain AttributeError, while np.alltrue, np.sometrue and np.round_ say "was removed in the NumPy 2.0 release" with the replacement. All changes: NumPy 2 breaking changes.

Frequently asked questions

What replaces np.in1d?

np.isin(a, b). Add .ravel() if you need in1d's flattened output for multi-dimensional a.

What replaces np.trapz?

np.trapezoid (NumPy 2.0+) or scipy.integrate.trapezoid.

Written with AI assistance. Measured on 2026-10-24 on Linux with Python 3.11.17 and numpy 2.3.5 and 2.4.6. The script ran verbatim and output was pasted unedited (paths shortened). PlainTables is our extension; NumPy is free.