Answers.Body: <p>This is a common Python pattern where packages expose their important classes at a higher level for convenience while maintaining organized internal structure. The actual implementation is in <code>torch.distributions.normal.Normal</code>, but it's <a href="https://github.com/pytorch/pytorch/blob/main/torch/distributions/__init__.py" rel="nofollow noreferrer">registered</a> in <code>torch.distributions.__init__.py</code> to be directly accessible as shown below.</p>
  <pre><code>from .normal import Normal
  
  __all__ = [... &quot;Normal&quot;,...]
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-12-10T06:41:47.530Z
Answers.Text: Thanks! But why use `from .normal import Normal` instead of `from normal import Normal`, since __init__.py and normal.py are in the same directory?
Answers.UserDisplayName: AStudent
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-12-10T06:48:19.423Z
Answers.Text: That is the correct *relative* import to ensure that Python will look for the normal.py module relative to the current package. Yours is *absolute* import from the global Python module namespace which assumes that the normal.py module has been already installed as part of the Python venv or is accessible as a top-level module. Of course the relative one is safer and better as public API. Hope this clarifies which is not AI theory but Python module import programming question.
Answers.UserDisplayName: cinch
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-12-10T06:49:06.217Z
Answers.Text: In addition, since `from .normal import Normal` already gets `Normal`, why do we still need `__all__ = [... "Normal",...]`?
Answers.UserDisplayName: AStudent
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-12-10T06:51:26.717Z
Answers.Text: The ```__all__``` attribute controls what is publicly accessible when someone imports the module or package using import *. This gives you the ability to hide internal implementation details and only expose the necessary classes, functions, or variables that make up the module's "public API". Some programmers might be lazy and just import *, where they can still invoke Normal module.
Answers.UserDisplayName: cinch
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-12-10T06:58:21.133Z
Answers.Text: If you consider my answer is helpful or resolved your lingering confusion, please upvote or accept it. Thank you.
Answers.UserDisplayName: cinch
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-12-10T07:00:40.013Z
Answers.Text: Your answer is really helpful! But I'm a new asker, so I cannot upvote until I have 15 reputations... I don't know why the platform designed this rule.
Answers.UserDisplayName: AStudent
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-12-10T07:02:19.983Z
Answers.Text: Yes I know, but I'm sure you can accept answer by clicking near the answer icon.
Answers.UserDisplayName: cinch
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-12-10T07:05:58.163Z
Answers.Text: Ok! I guess I have done that. Please let me know if I have not successfully done so.
Answers.UserDisplayName: AStudent
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-12-10T10:47:34.530Z
Answers.Text: Programming questions are off-topic here. Please, vote to close them instead of answering them. See https://ai.stackexchange.com/help/on-topic
Answers.UserDisplayName: nbro
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-12-10T01:10:50.773Z
Answers.LastActivityDate: 2024-12-10T01:10:50.773Z
Answers.UserDisplayName: cinch
Body: <p>I only see &quot;torch.distributions.normal.Normal&quot; in the official documents but never see &quot;torch.distributions.Normal&quot;. However, I sometimes see people use &quot;torch.distributions.Normal&quot; in their codes in Github. Could anyone explain if there is any difference between these two usages? Thanks a lot!</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-12-10T10:47:21.537Z
Comments.Text: Programming questions or questions about specific software are off-topic here. See https://ai.stackexchange.com/help/on-topic.
Comments.UserDisplayName: nbro
Tags: <pytorch><normal-distribution>
Title: Any Difference between "torch.distributions.normal.Normal" v.s. "torch.distributions.Normal"
UserDisplayName: AStudent
ThreadText: # Any Difference between "torch.distributions.normal.Normal" v.s. "torch.distributions.Normal"
  
  (Asked by: username_0 on 2024-12-10)
  
  I only see "torch.distributions.normal.Normal" in the official documents but never see "torch.distributions.Normal". However, I sometimes see people use "torch.distributions.Normal" in their codes in Github. Could anyone explain if there is any difference between these two usages? Thanks a lot!
  
  **Tags:** pytorch, normal-distribution
  
  > **Comments:**
  > **username_1**: Programming questions or questions about specific software are off-topic here. See https://ai.stackexchange.com/help/on-topic.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2024-12-10. Score: 0 | Accepted answer
  
  This is a common Python pattern where packages expose their important classes at a higher level for convenience while maintaining organized internal structure. The actual implementation is in `torch.distributions.normal.Normal`, but it's [registered](https://github.com/pytorch/pytorch/blob/main/torch/distributions/__init__.py) in `torch.distributions.__init__.py` to be directly accessible as shown below.
  
  ```
  from .normal import Normal
  
  __all__ = [... "Normal",...]
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks! But why use `from .normal import Normal` instead of `from normal import Normal`, since __init__.py and normal.py are in the same directory?  
  > **username_2**: That is the correct *relative* import to ensure that Python will look for the normal.py module relative to the current package. Yours is *absolute* import from the global Python module namespace which assumes that the normal.py module has been already installed as part of the Python venv or is accessible as a top-level module. Of course the relative one is safer and better as public API. Hope this clarifies which is not AI theory but Python module import programming question.  
  > **username_0**: In addition, since `from .normal import Normal` already gets `Normal`, why do we still need `__all__ = [... "Normal",...]`?  
  > **username_2**: The ```__all__``` attribute controls what is publicly accessible when someone imports the module or package using import *. This gives you the ability to hide internal implementation details and only expose the necessary classes, functions, or variables that make up the module's "public API". Some programmers might be lazy and just import *, where they can still invoke Normal module.  
  > **username_2**: If you consider my answer is helpful or resolved your lingering confusion, please upvote or accept it. Thank you.  
  > **username_0**: Your answer is really helpful! But I'm a new asker, so I cannot upvote until I have 15 reputations... I don't know why the platform designed this rule.  
  > **username_2**: Yes I know, but I'm sure you can accept answer by clicking near the answer icon.  
  > **username_0**: Ok! I guess I have done that. Please let me know if I have not successfully done so.  
  > **username_1**: Programming questions are off-topic here. Please, vote to close them instead of answering them. See https://ai.stackexchange.com/help/on-topic  
  
  ---
  
  