Tissuebox
Tissuebox

Reputation: 1056

numpy having no "isin" attribute

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?

Upvotes: 14

Views: 24120

Answers (3)

hpaulj
hpaulj

Reputation: 231385

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.

Upvotes: 8

MSeifert
MSeifert

Reputation: 152677

The isin function was added in NumPy 1.13:

New np.isin function, improves on in1d.

You're probably using an older version.

Upvotes: 17

Mad Physicist
Mad Physicist

Reputation: 114330

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.

Upvotes: 12

Related Questions