15

I tried using the np.isin() function but everytime I do, it returns me the error:

AttributeError: 'module' object has no attribute 'isin' 

here is exactly what I do

import numpy as np a = np.arange(9).reshape((3,3)) test = np.arange(5) print np.isin(a, test) 

I havent found any information about this problem, I use the latest version of numpy and havent had any problem with other numpy module, why does it returns me this error?

4
  • shouldn't it be np.sin() ? Commented Jul 11, 2017 at 21:51
  • 1
    @ksai No, user is asking for np.isin. @Tissuebox It works for me in Python3. Commented Jul 11, 2017 at 21:52
  • 2
    np.sin() returns the sinus of a number, np.isin() is a completly different thing Commented Jul 11, 2017 at 21:52
  • 1
    @Tissuebox. It was a close call between "imaginary sinus" and "is in" :) Commented Jul 11, 2017 at 22:01

3 Answers 3

17

The isin function was added in NumPy 1.13:

New np.isin function, improves on in1d.

You're probably using an older version.

Sign up to request clarification or add additional context in comments.

Comments

12

Reading through the Notes section of the docs shows

New in version 1.13.0.

I suspect that if you do

print(np.__version__) 

you will see something less than 1.13.0.

Comments

8

Following the [source] link in the docs I find that:

def isin(element, test_elements, assume_unique=False, invert=False): "..." element = np.asarray(element) return in1d(element, test_elements, assume_unique=assume_unique, invert=invert).reshape(element.shape) 

It's not doing anything that you can't already do with in1d.

The containing file can be downloaded, and used from your own directory. It has an enhanced unique.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.