Python package ismember returns array elements that are members of set array.
Project description
ismember
- 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ismember-1.0.0.tar.gz
(5.9 kB
view details)
Built Distribution
File details
Details for the file ismember-1.0.0.tar.gz
.
File metadata
- Download URL: ismember-1.0.0.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0724b9ec6d7e924218aa17ffdd7a225eafe2c142bbdaffa986c58ab379c834ea |
|
MD5 | 9c8c16bd1f901ff1214f8958bd0bb1e7 |
|
BLAKE2b-256 | 49ff11d118b1483aa96d9cccb92a540a6c6ac1a8d8361643163b113aa8c2f276 |
File details
Details for the file ismember-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: ismember-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec38a9f3fd6106930246c44b3856bcf510f1bac442a6805f8c45f19f32864a50 |
|
MD5 | 4ed176a558d7a84164ff776f452e2842 |
|
BLAKE2b-256 | 7e00b8a6ea5df5e12c205fb8e073d041d42e39b17093d0753a8c457c50c125c7 |