Skip to main content

Python package ismember returns array elements that are members of set array.

Project description

ismember

Python PyPI Version License Coffee Downloads

  • Python package ismember returns array elements that are members of set array

Contents

Installation

  • Install ismember from PyPI (recommended). ismember is compatible with Python 3.6+ and runs on Linux, MacOS X and Windows.
  • It is distributed under the MIT license.
pip install ismember
  • Alternatively, install ismember from the GitHub source:
git clone https://github.com/erdogant/ismember.git
cd ismember
python setup.py install

Import ismember package

from ismember import ismember

Example:

import numpy as np
from ismember import ismember

# Example with lists
a_vec  = [1,2,3,None]
b_vec  = [4,1,2]
[I,idx] = ismember(a_vec,b_vec)
np.array(a_vec)[I]
np.array(b_vec)[idx]

# Example with DataFrames
a_vec = pd.DataFrame(['aap','None','mies','aap','boom','mies',None,'mies','mies','pies',None])
b_vec = pd.DataFrame([None,'mies','mies','pies',None])
I, idx = ismember(a_vec,b_vec)
a_vec.values[I]
b_vec.values[idx]

a_vec = np.array([1,2,3,None])
b_vec = np.array([1,2,4])
I, idx = ismember(a_vec,b_vec)
a_vec[I]
b_vec[idx]

# Example with Numpy array
a_vec = np.array(['boom','aap','mies','aap'])
b_vec = np.array(['aap','boom','aap'])
I, idx = ismember(a_vec,b_vec)
a_vec[I]
b_vec[idx]

# Example with matrices
# Create two random matrices
a_vec = np.random.randint(0,10,(5,8))
b_vec = np.random.randint(0,10,(5,10))

# Row-wise comparison
Iloc, idx = ismember(a_vec, b_vec, 'elementwise')
# Print results for the first row:
a_vec[i,Iloc[0]]==b_vec[i,idx[0]]

# Row wise comparison
a_vec = np.array(((1, 2, 3), (4, 5, 6), (7, 8, 9), (10, 11, 12)))
b_vec = np.array(((4, 5, 6), (7, 8, 0)))
Iloc, idx = ismember(a_vec, b_vec, 'rows')

References

Maintainer

  • Erdogan Taskesen, github: erdogant
  • Contributions are welcome.
  • If you wish to buy me a Coffee for this work, it is very appreciated :)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ismember-0.2.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

ismember-0.2.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file ismember-0.2.0.tar.gz.

File metadata

  • Download URL: ismember-0.2.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.8

File hashes

Hashes for ismember-0.2.0.tar.gz
Algorithm Hash digest
SHA256 310df2ab1497a441203cd1ab111c65aa3684656475d1b6361499ae29fb3fba49
MD5 beb4e9c14a4cdf62c49f522de9661d4c
BLAKE2b-256 69ca210f50cb64f1caf4e795a4b7e83609fb063f296d7b5cb199264895b0f5b7

See more details on using hashes here.

File details

Details for the file ismember-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: ismember-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.8

File hashes

Hashes for ismember-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 739d8dd159141164f1c5bf9f8d5d755d38bffda566a43fe8ffe8fa69608f5bbd
MD5 89bee4d54c419cd055f7e0c010dfb962
BLAKE2b-256 99c725dfe73d1ae368024e29bb7835bc2235614f72c8327266b8f347e1d6e0fe

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page