RuntimeWarning: invalid value encountered in log












1















I become this expression:
RuntimeWarning: invalid value encountered in log



while trying this:



def fct(a, b, c, d):
global u1
global u2
if np.all(c > 0) and np.all(a > 0) and np.all(u1 != 0) and np.all(u2 != 0):
return a, c, u1, u2

u1, u2 = np.log(0.6*c), (math.e**d)**0.5
F = np.log(a**2) + 6*[math.e**(-b)]/u1 + 3/u2
print( F )


any idea??










share|improve this question

























  • Specify the a,b,c,d parameters' values too, this function gave the message above, pls, to be able to help you

    – Geeocode
    Nov 14 '18 at 12:55













  • This condition np.all(c > 0) and np.all(a > 0) and np.all(u1 != 0) and np.all(u2 != 0) is exactly the case where none of the operations after the if block would fail. That means that, as the code is now, if you reach those operations at least one of them will fail. Maybe those should go within the if block?

    – jdehesa
    Nov 14 '18 at 13:11











  • Please move your edit from answers to question deleting your answer and editing your question, as it is the common on the SO-n and I'm trying to prevent you from getting downvotes to your "answer".

    – Geeocode
    Nov 14 '18 at 14:06
















1















I become this expression:
RuntimeWarning: invalid value encountered in log



while trying this:



def fct(a, b, c, d):
global u1
global u2
if np.all(c > 0) and np.all(a > 0) and np.all(u1 != 0) and np.all(u2 != 0):
return a, c, u1, u2

u1, u2 = np.log(0.6*c), (math.e**d)**0.5
F = np.log(a**2) + 6*[math.e**(-b)]/u1 + 3/u2
print( F )


any idea??










share|improve this question

























  • Specify the a,b,c,d parameters' values too, this function gave the message above, pls, to be able to help you

    – Geeocode
    Nov 14 '18 at 12:55













  • This condition np.all(c > 0) and np.all(a > 0) and np.all(u1 != 0) and np.all(u2 != 0) is exactly the case where none of the operations after the if block would fail. That means that, as the code is now, if you reach those operations at least one of them will fail. Maybe those should go within the if block?

    – jdehesa
    Nov 14 '18 at 13:11











  • Please move your edit from answers to question deleting your answer and editing your question, as it is the common on the SO-n and I'm trying to prevent you from getting downvotes to your "answer".

    – Geeocode
    Nov 14 '18 at 14:06














1












1








1








I become this expression:
RuntimeWarning: invalid value encountered in log



while trying this:



def fct(a, b, c, d):
global u1
global u2
if np.all(c > 0) and np.all(a > 0) and np.all(u1 != 0) and np.all(u2 != 0):
return a, c, u1, u2

u1, u2 = np.log(0.6*c), (math.e**d)**0.5
F = np.log(a**2) + 6*[math.e**(-b)]/u1 + 3/u2
print( F )


any idea??










share|improve this question
















I become this expression:
RuntimeWarning: invalid value encountered in log



while trying this:



def fct(a, b, c, d):
global u1
global u2
if np.all(c > 0) and np.all(a > 0) and np.all(u1 != 0) and np.all(u2 != 0):
return a, c, u1, u2

u1, u2 = np.log(0.6*c), (math.e**d)**0.5
F = np.log(a**2) + 6*[math.e**(-b)]/u1 + 3/u2
print( F )


any idea??







python numpy logging






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 13:09









Carlos Gonzalez

429511




429511










asked Nov 14 '18 at 12:39









PlopPlop

104




104













  • Specify the a,b,c,d parameters' values too, this function gave the message above, pls, to be able to help you

    – Geeocode
    Nov 14 '18 at 12:55













  • This condition np.all(c > 0) and np.all(a > 0) and np.all(u1 != 0) and np.all(u2 != 0) is exactly the case where none of the operations after the if block would fail. That means that, as the code is now, if you reach those operations at least one of them will fail. Maybe those should go within the if block?

    – jdehesa
    Nov 14 '18 at 13:11











  • Please move your edit from answers to question deleting your answer and editing your question, as it is the common on the SO-n and I'm trying to prevent you from getting downvotes to your "answer".

    – Geeocode
    Nov 14 '18 at 14:06



















  • Specify the a,b,c,d parameters' values too, this function gave the message above, pls, to be able to help you

    – Geeocode
    Nov 14 '18 at 12:55













  • This condition np.all(c > 0) and np.all(a > 0) and np.all(u1 != 0) and np.all(u2 != 0) is exactly the case where none of the operations after the if block would fail. That means that, as the code is now, if you reach those operations at least one of them will fail. Maybe those should go within the if block?

    – jdehesa
    Nov 14 '18 at 13:11











  • Please move your edit from answers to question deleting your answer and editing your question, as it is the common on the SO-n and I'm trying to prevent you from getting downvotes to your "answer".

    – Geeocode
    Nov 14 '18 at 14:06

















Specify the a,b,c,d parameters' values too, this function gave the message above, pls, to be able to help you

– Geeocode
Nov 14 '18 at 12:55







Specify the a,b,c,d parameters' values too, this function gave the message above, pls, to be able to help you

– Geeocode
Nov 14 '18 at 12:55















This condition np.all(c > 0) and np.all(a > 0) and np.all(u1 != 0) and np.all(u2 != 0) is exactly the case where none of the operations after the if block would fail. That means that, as the code is now, if you reach those operations at least one of them will fail. Maybe those should go within the if block?

– jdehesa
Nov 14 '18 at 13:11





This condition np.all(c > 0) and np.all(a > 0) and np.all(u1 != 0) and np.all(u2 != 0) is exactly the case where none of the operations after the if block would fail. That means that, as the code is now, if you reach those operations at least one of them will fail. Maybe those should go within the if block?

– jdehesa
Nov 14 '18 at 13:11













Please move your edit from answers to question deleting your answer and editing your question, as it is the common on the SO-n and I'm trying to prevent you from getting downvotes to your "answer".

– Geeocode
Nov 14 '18 at 14:06





Please move your edit from answers to question deleting your answer and editing your question, as it is the common on the SO-n and I'm trying to prevent you from getting downvotes to your "answer".

– Geeocode
Nov 14 '18 at 14:06












1 Answer
1






active

oldest

votes


















0














This error message can emerge at two expression your code contains:



np.log(0.6*c) and np.log(a**2)


in the for loop with:



np.random.normal()


you will get random numbers at this distribution, whose values will be negative numbers.



That's why np.log() will drop up the error message:



RuntimeWarning: invalid value encountered in log


Example:



np.random.normal(10,4,100)


Out:



array([ 8.04664247, 14.4991884 , 10.89789303, 13.37593183,  3.29981902,
16.6316143 , 10.64138342, 4.0459445 , 10.49192082, -3.04538967!!!!!,
13.30443781, 4.13345961, 12.06508196, 10.4286879 , 7.39431349,
12.36789249, 9.20424736, 11.13161087, 12.15404482, 12.69897663,
9.43633904, 12.77818913, 9.02926639, 4.78638573, 13.13104605,
12.71197993, 6.1550897 , 7.18496505, 4.3160573 , 9.12631992,
8.52408627, 12.45941119, 5.34780934, 5.7023213 , 13.53096085,
12.1087058 , 3.65110834, 5.15466232, 8.78768562, 12.54764999,
15.12211713, 3.26481809, 9.8623701 , 15.88784306, 5.83355467,
5.32775214, 8.81188865, 13.21886467, 6.78984216, 8.67260897,
7.06100605, 13.75314668, 15.56562533, 10.33916552, 7.72745465,
11.27606127, 11.56813697, 7.03177164, 10.63155512, 11.67072579,
11.70855769, 10.78372397, 5.11327436, 15.61581808, 9.53446815,
11.21806808, 11.2235412 , 7.68339223, 12.71484256, 9.99613038,
13.51834424, 7.73615596, 8.75145457, 13.02222188, 6.76757021,
13.03580839, 10.67504642, 15.36110384, 15.66816384, -0.0952157 !!!!!!!! ,
2.23551198, 11.21584659, 4.37791786, 5.45895529, 15.44411348,
14.7077441 , 14.52080519, 3.70418827, 5.03132122, 5.24810117,
16.35309566, 7.08504246, 6.81224092, 14.69274684, 8.43257572,
12.87468578, 7.01621364, 7.62879265, 7.14646032, 20.16254855])


Stepping into your function inside of np.log()



c = np.array([ 8.04664247, 14.4991884 , 10.89789303, 13.37593183,  3.29981902,
16.6316143 , 10.64138342, 4.0459445 , 10.49192082, -3.04538967,
13.30443781, 4.13345961, 12.06508196, 10.4286879 , 7.39431349,
12.36789249, 9.20424736, 11.13161087, 12.15404482, 12.69897663,
9.43633904, 12.77818913, 9.02926639, 4.78638573, 13.13104605,
12.71197993, 6.1550897 , 7.18496505, 4.3160573 , 9.12631992,
8.52408627, 12.45941119, 5.34780934, 5.7023213 , 13.53096085,
12.1087058 , 3.65110834, 5.15466232, 8.78768562, 12.54764999,
15.12211713, 3.26481809, 9.8623701 , 15.88784306, 5.83355467,
5.32775214, 8.81188865, 13.21886467, 6.78984216, 8.67260897,
7.06100605, 13.75314668, 15.56562533, 10.33916552, 7.72745465,
11.27606127, 11.56813697, 7.03177164, 10.63155512, 11.67072579,
11.70855769, 10.78372397, 5.11327436, 15.61581808, 9.53446815,
11.21806808, 11.2235412 , 7.68339223, 12.71484256, 9.99613038,
13.51834424, 7.73615596, 8.75145457, 13.02222188, 6.76757021,
13.03580839, 10.67504642, 15.36110384, 15.66816384, -0.0952157 ,
2.23551198, 11.21584659, 4.37791786, 5.45895529, 15.44411348,
14.7077441 , 14.52080519, 3.70418827, 5.03132122, 5.24810117,
16.35309566, 7.08504246, 6.81224092, 14.69274684, 8.43257572,
12.87468578, 7.01621364, 7.62879265, 7.14646032, 20.16254855])

print(np.log(0.6*c))


Out:



[1.5744293  2.16326705 1.87774385 2.08263134 0.683042   2.30047974
1.85392487 0.8868894 1.83977989 nan!!!! 2.07727203 0.90828911
1.97948987 1.83373484 1.48988563 2.00427818 1.70883942 1.89896326
1.9868364 2.03069579 1.73374247 2.03691412 1.6896455 1.05494996
2.06415373 2.03171923 1.30645371 1.46116503 0.9515167 1.70033691
1.63207021 2.01165063 1.16586138 1.23004771 2.09415483 1.98309906
0.78420515 1.12907599 1.66252576 2.01870777 2.20533276 0.67237842
1.77790089 2.25472861 1.25280091 1.16210379 1.66527617 2.07081933
1.40460207 1.64934404 1.44376192 2.11044202 2.23423935 1.82511354
1.5339539 1.91185638 1.93742888 1.43961306 1.85300085 1.94625801
1.94949438 1.86721233 1.12101435 2.23745876 1.74408784 1.90670008
1.90718784 1.52823552 2.03194439 1.79137243 2.09322197 1.53507929
1.6583943 2.05583165 1.40131649 2.05687444 1.85708328 2.22101297
2.24080525 nan!!!!! 0.29364465 1.90650203 0.96574761 1.18643181
2.2264023 2.17754854 2.16475684 0.79863852 1.10485699 1.14704071
2.28359159 1.44716024 1.40789551 2.17652834 1.62127664 2.04443742
1.43739808 1.52110397 1.45579155 2.49300123]
/untitled0.py:37: RuntimeWarning: invalid value encountered in log





share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53300465%2fruntimewarning-invalid-value-encountered-in-log%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    This error message can emerge at two expression your code contains:



    np.log(0.6*c) and np.log(a**2)


    in the for loop with:



    np.random.normal()


    you will get random numbers at this distribution, whose values will be negative numbers.



    That's why np.log() will drop up the error message:



    RuntimeWarning: invalid value encountered in log


    Example:



    np.random.normal(10,4,100)


    Out:



    array([ 8.04664247, 14.4991884 , 10.89789303, 13.37593183,  3.29981902,
    16.6316143 , 10.64138342, 4.0459445 , 10.49192082, -3.04538967!!!!!,
    13.30443781, 4.13345961, 12.06508196, 10.4286879 , 7.39431349,
    12.36789249, 9.20424736, 11.13161087, 12.15404482, 12.69897663,
    9.43633904, 12.77818913, 9.02926639, 4.78638573, 13.13104605,
    12.71197993, 6.1550897 , 7.18496505, 4.3160573 , 9.12631992,
    8.52408627, 12.45941119, 5.34780934, 5.7023213 , 13.53096085,
    12.1087058 , 3.65110834, 5.15466232, 8.78768562, 12.54764999,
    15.12211713, 3.26481809, 9.8623701 , 15.88784306, 5.83355467,
    5.32775214, 8.81188865, 13.21886467, 6.78984216, 8.67260897,
    7.06100605, 13.75314668, 15.56562533, 10.33916552, 7.72745465,
    11.27606127, 11.56813697, 7.03177164, 10.63155512, 11.67072579,
    11.70855769, 10.78372397, 5.11327436, 15.61581808, 9.53446815,
    11.21806808, 11.2235412 , 7.68339223, 12.71484256, 9.99613038,
    13.51834424, 7.73615596, 8.75145457, 13.02222188, 6.76757021,
    13.03580839, 10.67504642, 15.36110384, 15.66816384, -0.0952157 !!!!!!!! ,
    2.23551198, 11.21584659, 4.37791786, 5.45895529, 15.44411348,
    14.7077441 , 14.52080519, 3.70418827, 5.03132122, 5.24810117,
    16.35309566, 7.08504246, 6.81224092, 14.69274684, 8.43257572,
    12.87468578, 7.01621364, 7.62879265, 7.14646032, 20.16254855])


    Stepping into your function inside of np.log()



    c = np.array([ 8.04664247, 14.4991884 , 10.89789303, 13.37593183,  3.29981902,
    16.6316143 , 10.64138342, 4.0459445 , 10.49192082, -3.04538967,
    13.30443781, 4.13345961, 12.06508196, 10.4286879 , 7.39431349,
    12.36789249, 9.20424736, 11.13161087, 12.15404482, 12.69897663,
    9.43633904, 12.77818913, 9.02926639, 4.78638573, 13.13104605,
    12.71197993, 6.1550897 , 7.18496505, 4.3160573 , 9.12631992,
    8.52408627, 12.45941119, 5.34780934, 5.7023213 , 13.53096085,
    12.1087058 , 3.65110834, 5.15466232, 8.78768562, 12.54764999,
    15.12211713, 3.26481809, 9.8623701 , 15.88784306, 5.83355467,
    5.32775214, 8.81188865, 13.21886467, 6.78984216, 8.67260897,
    7.06100605, 13.75314668, 15.56562533, 10.33916552, 7.72745465,
    11.27606127, 11.56813697, 7.03177164, 10.63155512, 11.67072579,
    11.70855769, 10.78372397, 5.11327436, 15.61581808, 9.53446815,
    11.21806808, 11.2235412 , 7.68339223, 12.71484256, 9.99613038,
    13.51834424, 7.73615596, 8.75145457, 13.02222188, 6.76757021,
    13.03580839, 10.67504642, 15.36110384, 15.66816384, -0.0952157 ,
    2.23551198, 11.21584659, 4.37791786, 5.45895529, 15.44411348,
    14.7077441 , 14.52080519, 3.70418827, 5.03132122, 5.24810117,
    16.35309566, 7.08504246, 6.81224092, 14.69274684, 8.43257572,
    12.87468578, 7.01621364, 7.62879265, 7.14646032, 20.16254855])

    print(np.log(0.6*c))


    Out:



    [1.5744293  2.16326705 1.87774385 2.08263134 0.683042   2.30047974
    1.85392487 0.8868894 1.83977989 nan!!!! 2.07727203 0.90828911
    1.97948987 1.83373484 1.48988563 2.00427818 1.70883942 1.89896326
    1.9868364 2.03069579 1.73374247 2.03691412 1.6896455 1.05494996
    2.06415373 2.03171923 1.30645371 1.46116503 0.9515167 1.70033691
    1.63207021 2.01165063 1.16586138 1.23004771 2.09415483 1.98309906
    0.78420515 1.12907599 1.66252576 2.01870777 2.20533276 0.67237842
    1.77790089 2.25472861 1.25280091 1.16210379 1.66527617 2.07081933
    1.40460207 1.64934404 1.44376192 2.11044202 2.23423935 1.82511354
    1.5339539 1.91185638 1.93742888 1.43961306 1.85300085 1.94625801
    1.94949438 1.86721233 1.12101435 2.23745876 1.74408784 1.90670008
    1.90718784 1.52823552 2.03194439 1.79137243 2.09322197 1.53507929
    1.6583943 2.05583165 1.40131649 2.05687444 1.85708328 2.22101297
    2.24080525 nan!!!!! 0.29364465 1.90650203 0.96574761 1.18643181
    2.2264023 2.17754854 2.16475684 0.79863852 1.10485699 1.14704071
    2.28359159 1.44716024 1.40789551 2.17652834 1.62127664 2.04443742
    1.43739808 1.52110397 1.45579155 2.49300123]
    /untitled0.py:37: RuntimeWarning: invalid value encountered in log





    share|improve this answer






























      0














      This error message can emerge at two expression your code contains:



      np.log(0.6*c) and np.log(a**2)


      in the for loop with:



      np.random.normal()


      you will get random numbers at this distribution, whose values will be negative numbers.



      That's why np.log() will drop up the error message:



      RuntimeWarning: invalid value encountered in log


      Example:



      np.random.normal(10,4,100)


      Out:



      array([ 8.04664247, 14.4991884 , 10.89789303, 13.37593183,  3.29981902,
      16.6316143 , 10.64138342, 4.0459445 , 10.49192082, -3.04538967!!!!!,
      13.30443781, 4.13345961, 12.06508196, 10.4286879 , 7.39431349,
      12.36789249, 9.20424736, 11.13161087, 12.15404482, 12.69897663,
      9.43633904, 12.77818913, 9.02926639, 4.78638573, 13.13104605,
      12.71197993, 6.1550897 , 7.18496505, 4.3160573 , 9.12631992,
      8.52408627, 12.45941119, 5.34780934, 5.7023213 , 13.53096085,
      12.1087058 , 3.65110834, 5.15466232, 8.78768562, 12.54764999,
      15.12211713, 3.26481809, 9.8623701 , 15.88784306, 5.83355467,
      5.32775214, 8.81188865, 13.21886467, 6.78984216, 8.67260897,
      7.06100605, 13.75314668, 15.56562533, 10.33916552, 7.72745465,
      11.27606127, 11.56813697, 7.03177164, 10.63155512, 11.67072579,
      11.70855769, 10.78372397, 5.11327436, 15.61581808, 9.53446815,
      11.21806808, 11.2235412 , 7.68339223, 12.71484256, 9.99613038,
      13.51834424, 7.73615596, 8.75145457, 13.02222188, 6.76757021,
      13.03580839, 10.67504642, 15.36110384, 15.66816384, -0.0952157 !!!!!!!! ,
      2.23551198, 11.21584659, 4.37791786, 5.45895529, 15.44411348,
      14.7077441 , 14.52080519, 3.70418827, 5.03132122, 5.24810117,
      16.35309566, 7.08504246, 6.81224092, 14.69274684, 8.43257572,
      12.87468578, 7.01621364, 7.62879265, 7.14646032, 20.16254855])


      Stepping into your function inside of np.log()



      c = np.array([ 8.04664247, 14.4991884 , 10.89789303, 13.37593183,  3.29981902,
      16.6316143 , 10.64138342, 4.0459445 , 10.49192082, -3.04538967,
      13.30443781, 4.13345961, 12.06508196, 10.4286879 , 7.39431349,
      12.36789249, 9.20424736, 11.13161087, 12.15404482, 12.69897663,
      9.43633904, 12.77818913, 9.02926639, 4.78638573, 13.13104605,
      12.71197993, 6.1550897 , 7.18496505, 4.3160573 , 9.12631992,
      8.52408627, 12.45941119, 5.34780934, 5.7023213 , 13.53096085,
      12.1087058 , 3.65110834, 5.15466232, 8.78768562, 12.54764999,
      15.12211713, 3.26481809, 9.8623701 , 15.88784306, 5.83355467,
      5.32775214, 8.81188865, 13.21886467, 6.78984216, 8.67260897,
      7.06100605, 13.75314668, 15.56562533, 10.33916552, 7.72745465,
      11.27606127, 11.56813697, 7.03177164, 10.63155512, 11.67072579,
      11.70855769, 10.78372397, 5.11327436, 15.61581808, 9.53446815,
      11.21806808, 11.2235412 , 7.68339223, 12.71484256, 9.99613038,
      13.51834424, 7.73615596, 8.75145457, 13.02222188, 6.76757021,
      13.03580839, 10.67504642, 15.36110384, 15.66816384, -0.0952157 ,
      2.23551198, 11.21584659, 4.37791786, 5.45895529, 15.44411348,
      14.7077441 , 14.52080519, 3.70418827, 5.03132122, 5.24810117,
      16.35309566, 7.08504246, 6.81224092, 14.69274684, 8.43257572,
      12.87468578, 7.01621364, 7.62879265, 7.14646032, 20.16254855])

      print(np.log(0.6*c))


      Out:



      [1.5744293  2.16326705 1.87774385 2.08263134 0.683042   2.30047974
      1.85392487 0.8868894 1.83977989 nan!!!! 2.07727203 0.90828911
      1.97948987 1.83373484 1.48988563 2.00427818 1.70883942 1.89896326
      1.9868364 2.03069579 1.73374247 2.03691412 1.6896455 1.05494996
      2.06415373 2.03171923 1.30645371 1.46116503 0.9515167 1.70033691
      1.63207021 2.01165063 1.16586138 1.23004771 2.09415483 1.98309906
      0.78420515 1.12907599 1.66252576 2.01870777 2.20533276 0.67237842
      1.77790089 2.25472861 1.25280091 1.16210379 1.66527617 2.07081933
      1.40460207 1.64934404 1.44376192 2.11044202 2.23423935 1.82511354
      1.5339539 1.91185638 1.93742888 1.43961306 1.85300085 1.94625801
      1.94949438 1.86721233 1.12101435 2.23745876 1.74408784 1.90670008
      1.90718784 1.52823552 2.03194439 1.79137243 2.09322197 1.53507929
      1.6583943 2.05583165 1.40131649 2.05687444 1.85708328 2.22101297
      2.24080525 nan!!!!! 0.29364465 1.90650203 0.96574761 1.18643181
      2.2264023 2.17754854 2.16475684 0.79863852 1.10485699 1.14704071
      2.28359159 1.44716024 1.40789551 2.17652834 1.62127664 2.04443742
      1.43739808 1.52110397 1.45579155 2.49300123]
      /untitled0.py:37: RuntimeWarning: invalid value encountered in log





      share|improve this answer




























        0












        0








        0







        This error message can emerge at two expression your code contains:



        np.log(0.6*c) and np.log(a**2)


        in the for loop with:



        np.random.normal()


        you will get random numbers at this distribution, whose values will be negative numbers.



        That's why np.log() will drop up the error message:



        RuntimeWarning: invalid value encountered in log


        Example:



        np.random.normal(10,4,100)


        Out:



        array([ 8.04664247, 14.4991884 , 10.89789303, 13.37593183,  3.29981902,
        16.6316143 , 10.64138342, 4.0459445 , 10.49192082, -3.04538967!!!!!,
        13.30443781, 4.13345961, 12.06508196, 10.4286879 , 7.39431349,
        12.36789249, 9.20424736, 11.13161087, 12.15404482, 12.69897663,
        9.43633904, 12.77818913, 9.02926639, 4.78638573, 13.13104605,
        12.71197993, 6.1550897 , 7.18496505, 4.3160573 , 9.12631992,
        8.52408627, 12.45941119, 5.34780934, 5.7023213 , 13.53096085,
        12.1087058 , 3.65110834, 5.15466232, 8.78768562, 12.54764999,
        15.12211713, 3.26481809, 9.8623701 , 15.88784306, 5.83355467,
        5.32775214, 8.81188865, 13.21886467, 6.78984216, 8.67260897,
        7.06100605, 13.75314668, 15.56562533, 10.33916552, 7.72745465,
        11.27606127, 11.56813697, 7.03177164, 10.63155512, 11.67072579,
        11.70855769, 10.78372397, 5.11327436, 15.61581808, 9.53446815,
        11.21806808, 11.2235412 , 7.68339223, 12.71484256, 9.99613038,
        13.51834424, 7.73615596, 8.75145457, 13.02222188, 6.76757021,
        13.03580839, 10.67504642, 15.36110384, 15.66816384, -0.0952157 !!!!!!!! ,
        2.23551198, 11.21584659, 4.37791786, 5.45895529, 15.44411348,
        14.7077441 , 14.52080519, 3.70418827, 5.03132122, 5.24810117,
        16.35309566, 7.08504246, 6.81224092, 14.69274684, 8.43257572,
        12.87468578, 7.01621364, 7.62879265, 7.14646032, 20.16254855])


        Stepping into your function inside of np.log()



        c = np.array([ 8.04664247, 14.4991884 , 10.89789303, 13.37593183,  3.29981902,
        16.6316143 , 10.64138342, 4.0459445 , 10.49192082, -3.04538967,
        13.30443781, 4.13345961, 12.06508196, 10.4286879 , 7.39431349,
        12.36789249, 9.20424736, 11.13161087, 12.15404482, 12.69897663,
        9.43633904, 12.77818913, 9.02926639, 4.78638573, 13.13104605,
        12.71197993, 6.1550897 , 7.18496505, 4.3160573 , 9.12631992,
        8.52408627, 12.45941119, 5.34780934, 5.7023213 , 13.53096085,
        12.1087058 , 3.65110834, 5.15466232, 8.78768562, 12.54764999,
        15.12211713, 3.26481809, 9.8623701 , 15.88784306, 5.83355467,
        5.32775214, 8.81188865, 13.21886467, 6.78984216, 8.67260897,
        7.06100605, 13.75314668, 15.56562533, 10.33916552, 7.72745465,
        11.27606127, 11.56813697, 7.03177164, 10.63155512, 11.67072579,
        11.70855769, 10.78372397, 5.11327436, 15.61581808, 9.53446815,
        11.21806808, 11.2235412 , 7.68339223, 12.71484256, 9.99613038,
        13.51834424, 7.73615596, 8.75145457, 13.02222188, 6.76757021,
        13.03580839, 10.67504642, 15.36110384, 15.66816384, -0.0952157 ,
        2.23551198, 11.21584659, 4.37791786, 5.45895529, 15.44411348,
        14.7077441 , 14.52080519, 3.70418827, 5.03132122, 5.24810117,
        16.35309566, 7.08504246, 6.81224092, 14.69274684, 8.43257572,
        12.87468578, 7.01621364, 7.62879265, 7.14646032, 20.16254855])

        print(np.log(0.6*c))


        Out:



        [1.5744293  2.16326705 1.87774385 2.08263134 0.683042   2.30047974
        1.85392487 0.8868894 1.83977989 nan!!!! 2.07727203 0.90828911
        1.97948987 1.83373484 1.48988563 2.00427818 1.70883942 1.89896326
        1.9868364 2.03069579 1.73374247 2.03691412 1.6896455 1.05494996
        2.06415373 2.03171923 1.30645371 1.46116503 0.9515167 1.70033691
        1.63207021 2.01165063 1.16586138 1.23004771 2.09415483 1.98309906
        0.78420515 1.12907599 1.66252576 2.01870777 2.20533276 0.67237842
        1.77790089 2.25472861 1.25280091 1.16210379 1.66527617 2.07081933
        1.40460207 1.64934404 1.44376192 2.11044202 2.23423935 1.82511354
        1.5339539 1.91185638 1.93742888 1.43961306 1.85300085 1.94625801
        1.94949438 1.86721233 1.12101435 2.23745876 1.74408784 1.90670008
        1.90718784 1.52823552 2.03194439 1.79137243 2.09322197 1.53507929
        1.6583943 2.05583165 1.40131649 2.05687444 1.85708328 2.22101297
        2.24080525 nan!!!!! 0.29364465 1.90650203 0.96574761 1.18643181
        2.2264023 2.17754854 2.16475684 0.79863852 1.10485699 1.14704071
        2.28359159 1.44716024 1.40789551 2.17652834 1.62127664 2.04443742
        1.43739808 1.52110397 1.45579155 2.49300123]
        /untitled0.py:37: RuntimeWarning: invalid value encountered in log





        share|improve this answer















        This error message can emerge at two expression your code contains:



        np.log(0.6*c) and np.log(a**2)


        in the for loop with:



        np.random.normal()


        you will get random numbers at this distribution, whose values will be negative numbers.



        That's why np.log() will drop up the error message:



        RuntimeWarning: invalid value encountered in log


        Example:



        np.random.normal(10,4,100)


        Out:



        array([ 8.04664247, 14.4991884 , 10.89789303, 13.37593183,  3.29981902,
        16.6316143 , 10.64138342, 4.0459445 , 10.49192082, -3.04538967!!!!!,
        13.30443781, 4.13345961, 12.06508196, 10.4286879 , 7.39431349,
        12.36789249, 9.20424736, 11.13161087, 12.15404482, 12.69897663,
        9.43633904, 12.77818913, 9.02926639, 4.78638573, 13.13104605,
        12.71197993, 6.1550897 , 7.18496505, 4.3160573 , 9.12631992,
        8.52408627, 12.45941119, 5.34780934, 5.7023213 , 13.53096085,
        12.1087058 , 3.65110834, 5.15466232, 8.78768562, 12.54764999,
        15.12211713, 3.26481809, 9.8623701 , 15.88784306, 5.83355467,
        5.32775214, 8.81188865, 13.21886467, 6.78984216, 8.67260897,
        7.06100605, 13.75314668, 15.56562533, 10.33916552, 7.72745465,
        11.27606127, 11.56813697, 7.03177164, 10.63155512, 11.67072579,
        11.70855769, 10.78372397, 5.11327436, 15.61581808, 9.53446815,
        11.21806808, 11.2235412 , 7.68339223, 12.71484256, 9.99613038,
        13.51834424, 7.73615596, 8.75145457, 13.02222188, 6.76757021,
        13.03580839, 10.67504642, 15.36110384, 15.66816384, -0.0952157 !!!!!!!! ,
        2.23551198, 11.21584659, 4.37791786, 5.45895529, 15.44411348,
        14.7077441 , 14.52080519, 3.70418827, 5.03132122, 5.24810117,
        16.35309566, 7.08504246, 6.81224092, 14.69274684, 8.43257572,
        12.87468578, 7.01621364, 7.62879265, 7.14646032, 20.16254855])


        Stepping into your function inside of np.log()



        c = np.array([ 8.04664247, 14.4991884 , 10.89789303, 13.37593183,  3.29981902,
        16.6316143 , 10.64138342, 4.0459445 , 10.49192082, -3.04538967,
        13.30443781, 4.13345961, 12.06508196, 10.4286879 , 7.39431349,
        12.36789249, 9.20424736, 11.13161087, 12.15404482, 12.69897663,
        9.43633904, 12.77818913, 9.02926639, 4.78638573, 13.13104605,
        12.71197993, 6.1550897 , 7.18496505, 4.3160573 , 9.12631992,
        8.52408627, 12.45941119, 5.34780934, 5.7023213 , 13.53096085,
        12.1087058 , 3.65110834, 5.15466232, 8.78768562, 12.54764999,
        15.12211713, 3.26481809, 9.8623701 , 15.88784306, 5.83355467,
        5.32775214, 8.81188865, 13.21886467, 6.78984216, 8.67260897,
        7.06100605, 13.75314668, 15.56562533, 10.33916552, 7.72745465,
        11.27606127, 11.56813697, 7.03177164, 10.63155512, 11.67072579,
        11.70855769, 10.78372397, 5.11327436, 15.61581808, 9.53446815,
        11.21806808, 11.2235412 , 7.68339223, 12.71484256, 9.99613038,
        13.51834424, 7.73615596, 8.75145457, 13.02222188, 6.76757021,
        13.03580839, 10.67504642, 15.36110384, 15.66816384, -0.0952157 ,
        2.23551198, 11.21584659, 4.37791786, 5.45895529, 15.44411348,
        14.7077441 , 14.52080519, 3.70418827, 5.03132122, 5.24810117,
        16.35309566, 7.08504246, 6.81224092, 14.69274684, 8.43257572,
        12.87468578, 7.01621364, 7.62879265, 7.14646032, 20.16254855])

        print(np.log(0.6*c))


        Out:



        [1.5744293  2.16326705 1.87774385 2.08263134 0.683042   2.30047974
        1.85392487 0.8868894 1.83977989 nan!!!! 2.07727203 0.90828911
        1.97948987 1.83373484 1.48988563 2.00427818 1.70883942 1.89896326
        1.9868364 2.03069579 1.73374247 2.03691412 1.6896455 1.05494996
        2.06415373 2.03171923 1.30645371 1.46116503 0.9515167 1.70033691
        1.63207021 2.01165063 1.16586138 1.23004771 2.09415483 1.98309906
        0.78420515 1.12907599 1.66252576 2.01870777 2.20533276 0.67237842
        1.77790089 2.25472861 1.25280091 1.16210379 1.66527617 2.07081933
        1.40460207 1.64934404 1.44376192 2.11044202 2.23423935 1.82511354
        1.5339539 1.91185638 1.93742888 1.43961306 1.85300085 1.94625801
        1.94949438 1.86721233 1.12101435 2.23745876 1.74408784 1.90670008
        1.90718784 1.52823552 2.03194439 1.79137243 2.09322197 1.53507929
        1.6583943 2.05583165 1.40131649 2.05687444 1.85708328 2.22101297
        2.24080525 nan!!!!! 0.29364465 1.90650203 0.96574761 1.18643181
        2.2264023 2.17754854 2.16475684 0.79863852 1.10485699 1.14704071
        2.28359159 1.44716024 1.40789551 2.17652834 1.62127664 2.04443742
        1.43739808 1.52110397 1.45579155 2.49300123]
        /untitled0.py:37: RuntimeWarning: invalid value encountered in log






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 14 '18 at 14:17

























        answered Nov 14 '18 at 13:11









        GeeocodeGeeocode

        2,3181820




        2,3181820






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53300465%2fruntimewarning-invalid-value-encountered-in-log%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Xamarin.iOS Cant Deploy on Iphone

            Glorious Revolution

            Dulmage-Mendelsohn matrix decomposition in Python