Arguments in python fast.ai function that are not in the function definition?












1












$begingroup$


I have been coming across function calls that use arguments that are not in the function definition. I would like to know how that works (i.e. how the compiler interprets this).



For example, this function call:



 interp.plot_confusion_matrix(figsize=(12,12), dpi=60)


uses the variables "figsize" and "dpi", but neither of them turn up in the definition of plot_confusion_matrix: help(interp.plot_confusion_matrix) gives:



plot_confusion_matrix(normalize: bool = False, title: str = 'Confusion matrix', 
cmap: Any = 'Blues', norm_dec: int = 2, slice_size: int = None, **kwargs) -> None
method of fastai.vision.learner.ClassificationInterpretation instance
Plot the confusion matrix, with `title` and using `cmap`.


Why is it not an error to use "figsize" and "dpi" in the function call if they are not arguments of the function? How does this work in python?










share|improve this question











$endgroup$

















    1












    $begingroup$


    I have been coming across function calls that use arguments that are not in the function definition. I would like to know how that works (i.e. how the compiler interprets this).



    For example, this function call:



     interp.plot_confusion_matrix(figsize=(12,12), dpi=60)


    uses the variables "figsize" and "dpi", but neither of them turn up in the definition of plot_confusion_matrix: help(interp.plot_confusion_matrix) gives:



    plot_confusion_matrix(normalize: bool = False, title: str = 'Confusion matrix', 
    cmap: Any = 'Blues', norm_dec: int = 2, slice_size: int = None, **kwargs) -> None
    method of fastai.vision.learner.ClassificationInterpretation instance
    Plot the confusion matrix, with `title` and using `cmap`.


    Why is it not an error to use "figsize" and "dpi" in the function call if they are not arguments of the function? How does this work in python?










    share|improve this question











    $endgroup$















      1












      1








      1





      $begingroup$


      I have been coming across function calls that use arguments that are not in the function definition. I would like to know how that works (i.e. how the compiler interprets this).



      For example, this function call:



       interp.plot_confusion_matrix(figsize=(12,12), dpi=60)


      uses the variables "figsize" and "dpi", but neither of them turn up in the definition of plot_confusion_matrix: help(interp.plot_confusion_matrix) gives:



      plot_confusion_matrix(normalize: bool = False, title: str = 'Confusion matrix', 
      cmap: Any = 'Blues', norm_dec: int = 2, slice_size: int = None, **kwargs) -> None
      method of fastai.vision.learner.ClassificationInterpretation instance
      Plot the confusion matrix, with `title` and using `cmap`.


      Why is it not an error to use "figsize" and "dpi" in the function call if they are not arguments of the function? How does this work in python?










      share|improve this question











      $endgroup$




      I have been coming across function calls that use arguments that are not in the function definition. I would like to know how that works (i.e. how the compiler interprets this).



      For example, this function call:



       interp.plot_confusion_matrix(figsize=(12,12), dpi=60)


      uses the variables "figsize" and "dpi", but neither of them turn up in the definition of plot_confusion_matrix: help(interp.plot_confusion_matrix) gives:



      plot_confusion_matrix(normalize: bool = False, title: str = 'Confusion matrix', 
      cmap: Any = 'Blues', norm_dec: int = 2, slice_size: int = None, **kwargs) -> None
      method of fastai.vision.learner.ClassificationInterpretation instance
      Plot the confusion matrix, with `title` and using `cmap`.


      Why is it not an error to use "figsize" and "dpi" in the function call if they are not arguments of the function? How does this work in python?







      python jupyter fastai






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 20 hours ago









      Davide Fiocco

      2044




      2044










      asked Feb 16 at 13:26









      user637140user637140

      383




      383






















          1 Answer
          1






          active

          oldest

          votes


















          0












          $begingroup$

          Those parameters are taken care of by **kwargs in the function definition.
          You can look how this is dealt with by the code in the fastai repo and looking for **kwargs in the function definition.

          Some explanations about how this works can be found on SO: https://stackoverflow.com/questions/3394835/use-of-args-and-kwargs.






          share|improve this answer











          $endgroup$













            Your Answer





            StackExchange.ifUsing("editor", function () {
            return StackExchange.using("mathjaxEditing", function () {
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
            });
            });
            }, "mathjax-editing");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "557"
            };
            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: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            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%2fdatascience.stackexchange.com%2fquestions%2f45685%2farguments-in-python-fast-ai-function-that-are-not-in-the-function-definition%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












            $begingroup$

            Those parameters are taken care of by **kwargs in the function definition.
            You can look how this is dealt with by the code in the fastai repo and looking for **kwargs in the function definition.

            Some explanations about how this works can be found on SO: https://stackoverflow.com/questions/3394835/use-of-args-and-kwargs.






            share|improve this answer











            $endgroup$


















              0












              $begingroup$

              Those parameters are taken care of by **kwargs in the function definition.
              You can look how this is dealt with by the code in the fastai repo and looking for **kwargs in the function definition.

              Some explanations about how this works can be found on SO: https://stackoverflow.com/questions/3394835/use-of-args-and-kwargs.






              share|improve this answer











              $endgroup$
















                0












                0








                0





                $begingroup$

                Those parameters are taken care of by **kwargs in the function definition.
                You can look how this is dealt with by the code in the fastai repo and looking for **kwargs in the function definition.

                Some explanations about how this works can be found on SO: https://stackoverflow.com/questions/3394835/use-of-args-and-kwargs.






                share|improve this answer











                $endgroup$



                Those parameters are taken care of by **kwargs in the function definition.
                You can look how this is dealt with by the code in the fastai repo and looking for **kwargs in the function definition.

                Some explanations about how this works can be found on SO: https://stackoverflow.com/questions/3394835/use-of-args-and-kwargs.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 2 days ago

























                answered 2 days ago









                Davide FioccoDavide Fiocco

                2044




                2044






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Data Science Stack Exchange!


                    • 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.


                    Use MathJax to format equations. MathJax reference.


                    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%2fdatascience.stackexchange.com%2fquestions%2f45685%2farguments-in-python-fast-ai-function-that-are-not-in-the-function-definition%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

                    How to label and detect the document text images

                    Vallis Paradisi

                    Tabula Rosettana