Code Monkey home page Code Monkey logo

ismember's Introduction

Hi there! I am sharing my knowledge with the world through my blogs and open-source GitHub projects.

Your ❤️ is important to keep maintaining my packages. It is awsome that there are readily millions of downloads but to keep the libraries alive, I often need to make all kinds of fixes. This can eat up my entire weekend and evenings. Yes, I do this for free and in my free time! There are various ways you can help. You can report bugs/ issues, or even better help out with fixing bugs or maybe adding new features! If you don't have the time or maybe you are still learning, you can also take a Medium Membership using my referral link to keep reading all my hands-on blogs and learn more :-) If you don't need that, there is always an easy way with Coffee :-) Cheers!

Buy Me a Coffee at ko-fi.com

A structured list of my repos

All Repos can be found in the Repositories section. If Sphinx pages are available, the link will directly go to the documentation pages.

Statistics Machine learning (Time)Series Vizualization Utils API
bnlearn clusteval findpeaks d3graph df2onehot googletrends
hnet classeval temporalrank d3heatmap pypickle slacki
distfit hgboost caerus treeplot ismember  
pca clustimage   kaplanmeier irelease  
thompson undouble   flameplot pypiplot  
benfordslaw     worldmap dicter  
      colourmap    
      imagesc    
      scatterd    
      d3blocks    

Find here my Pypi download stats

Overview of open issues

d3blocks bnlearn hnet distfit pca benfordslaw clustimage undouble clusteval classeval hgboost findpeaks d3graph d3heatmap treeplot kaplanmeier ismember dicter

ismember's People

Contributors

erdogant avatar leuraph avatar rw31415 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

rw31415 leuraph

ismember's Issues

Numpy `2.0.0` breaks `ismember`

What has changed

From Numpy's 2.0.0 release notes, we know that

When multi-dimensional inputs are passed to np.unique with return_inverse=True, the unique_inverse output is now shaped such that the input can be reconstructed directly using np.take(unique, unique_inverse) when axis=None, and np.take_along_axis(unique, unique_inverse, axis=axis) otherwise.

Breaking Example

In practice, this means that the unit tests of ismember fail and, e.g. the following code breaks when switching from numpy==1.26.0 to numpy==2.0.0:

boundaries = np.array([
    [1,2],
    [3,4],
    [6,7],
    [10,11]
])
local_edges = np.array([
    [6,7],
    [3,4],
    [12,3]
])
is_local_boundary = ismember.is_row_in(
    boundaries, local_edges)
print(is_local_boundary.shape)
local_boundaries = boundaries[is_local_boundary]
IndexError: boolean index did not match indexed array along axis 1; size of axis is 2 but size of corresponding boolean axis is 1

Explanation

  • numpy==2.0.0: is_local_boundary has shape (4,1)
  • numpy==1.26.0: is_local_boundary has shape (4,)

'rows' mode

Hi Erdogan,

Thank you for your work! The function works really well.

However it seems to me the ‘rows’ mode is a bit odd.

I tested these matrices in Matlab:

>> a = [1 2 3; 4 5 6; 7 8 9; 10 11 12]

a =

     1     2     3
     4     5     6
     7     8     9
    10    11    12

>> b = [4 5 6; 7 8 0]

b =

     4     5     6
     7     8     0

>> [Lia, Locb] = ismember(a, b, 'rows')

Lia =

  4×1 logical array

   0
   1
   0
   0


Locb =

     0
     1
     0
     0

Same code in Python throws an exception.

>>> a = np.array((
...     (1, 2, 3),
...     (4, 5, 6),
...     (7, 8, 9),
...     (10, 11, 12),
... ))
>>> b = np.array((
...     (4, 5, 6),
...     (7, 8, 0),
... ))
>>> ismember(a, b, 'rows')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/env/lib/python3.6/site-packages/ismember/ismember.py", line 47, in ismember
    if a_vec.shape[0]!=b_vec.shape[0]: raise Exception('Error: Input matrices should have same number of columns.')
Exception: Error: Input matrices should have same number of columns.

Transposing the matrices gives something, but it doesn't match the result from Matlab.

>>> Lia, Locb = ismember(a.T, b.T, 'rows')
>>> Lia
(array([False,  True,  True, False]), array([False,  True,  True, False]), array([False,  True, False, False]))
>>> Locb
(array([0, 1]), array([0, 1]), array([0]))

I am not an expert in NumPy or Matlab. Maybe I'm doing something wrong.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.