import theano.tensor as T
from theano import tensor as T
Is there a difference between the two or are they same? Which is better?
import theano.tensor as T
from theano import tensor as T
Is there a difference between the two or are they same? Which is better?
No, there's not. You're importing the same thing in both cases.
To read up on the differences between import module
and from module import foo
see this question
Although the SO posts linked in comments will probably give you the answer you are looking for, one thing I would like to add to the conversation is that the from import a.b
will only work if b
is a submodule of a
, but will raise an error if b
is not a module.
On the other hand, from a import b
will work even if b
is not a module (i.e., if it is a method of a
). Observe:
In [1]: import os.path
In [2]: from os import path
In [3]: import datetime.datetime
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-3-8466c53a2255> in <module>()
----> 1 import datetime.datetime
ImportError: No module named datetime
In [4]: from datetime import datetime
I think from a import b
is the preferred usage compared to import a.b
- at least it is the one that I have come across far more often. The as ...
part will operate the same in both cases.