Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Troubled by 1 instance of np.flatnonzero #21

Open
wgandler opened this issue Jun 4, 2022 · 3 comments
Open

Troubled by 1 instance of np.flatnonzero #21

wgandler opened this issue Jun 4, 2022 · 3 comments

Comments

@wgandler
Copy link

wgandler commented Jun 4, 2022

Hi,

I am troubled by 1 instance of np.flatnonzero. In _ Esum the lines:
if U_k is None:
U_k = np.flatnonzero(indices)
Removing 0 index makes U_k length 1 less than chi2 length, T_inv_k length, and log_p[k] length. I don't see why the zero index is removed.

                                     Sincerely,

                                 William Gandler
@wgandler wgandler changed the title Troubled by 2 instances of np.flatnonzero Troubled by 1 instance of np.flatnonzero Jun 4, 2022
@pmelchior
Copy link
Owner

Hello William. Are you asking about why that selection U_k = np.flatnonzero(indices) is done, or do you have trouble that is caused by this line?

@wgandler
Copy link
Author

wgandler commented Oct 11, 2022 via email

@pmelchior
Copy link
Owner

I'm not sure how this can happen. The relevant part of the code is this:

pygmmis/pygmmis.py

Lines 993 to 1001 in 87ad02d

if cutoff is not None:
indices = chi2 < cutoff
chi2 = chi2[indices]
if (covar is not None and covar.shape != (gmm.D, gmm.D)) or R is not None:
T_inv_k = T_inv_k[indices]
if U_k is None:
U_k = np.flatnonzero(indices)
else:
U_k = U_k[indices]

The array indices is of type bool, and the first step of setting U_k from its initial value None lists all non-zero (i.e. non-False) elements of indices.

The following code does exactly the same in a nutshell:

test = np.random.rand(10)
indices = test < 0.5
print(indices, np.flatnonzero(indices))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants