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

Possible fix for error: “ValueError: array must not contain infs or NaNs” #14

Closed
pedrotnascimento opened this issue Jul 23, 2017 · 0 comments

Comments

@pedrotnascimento
Copy link

Hi,
I received the error in subject and I looked for the reason in the source code.
I realized that my data, after the line below, in mca.py, has some of the values changed to "inf":
self.D_c = numpy.diag(1/numpy.sqrt(self.c))

then I inspect for the reason and I noticed that self.c had some 0.00000000 values.
So naturally, dividing 1/0 will give something wrong, although numpy didn't throw any error it didn't computed, but turned the value to "inf" and applied to self.D_c

So what I did was just alter the values that was 0 to some value next to 0( 0.00000000000001), and it did worked.

i'm sharing my code with you :

##my code
    # if self.c in the line below has any 0.0 then
    # self.D_c = numpy.diag(1/numpy.sqrt(self.c))
    # will occur division by 0, which numpy is not throwing
    # the code below intents to fix that error putting a number 
    # as close to 0 as founded by logs of numpy: decimal of 13 digits of 0
    # necessary use of panda 
  low_number = 0.00000000000001
  temp_dict = self.c.to_dict()
  temp_dtype = self.c.dtype
  for i in temp_dict:
  	if temp_dict[i] == 0:
  		temp_dict[i] = low_number
  self.c = pandas.Series(temp_dict, dtype=temp_dtype)
    ##end
  self.D_c = numpy.diag(1/numpy.sqrt(self.c))
esafak pushed a commit that referenced this issue Jul 26, 2017
@esafak esafak closed this as completed Jul 26, 2017
esafak pushed a commit that referenced this issue Jul 26, 2017
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