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))

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

# 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')
a_vec[Iloc]==b_vec[idx]

print(a_vec[Iloc])
[[4 5 6]]
print(b_vec[idx])
[[4 5 6]]

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.1.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

ismember-0.2.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ismember-0.2.1.tar.gz
  • Upload date:
  • Size: 5.1 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.1.tar.gz
Algorithm Hash digest
SHA256 0fe562ef7e81f1a02618893d28904d59afae57cb6cf0fe0a09ba6f96282915e9
MD5 7dd650ac85cf7aa6389a1d5528b3e77f
BLAKE2b-256 8b8bfc755d21bf7e5613a5c5922137e7c4486c31f35e3f84beceee67496c984c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ismember-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 6.3 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f2125e2759b55fe6eaf05cfaaa1d23af99e5d0638d9c3665bce65347a20c17c5
MD5 bc86ad2683212267ccba81fe50118261
BLAKE2b-256 49d74641637dfaec495fa46653251b2ce09ae2532aa2513bc4c589e80e3f1a28

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