I have created a module with multiple small user-defined functions. Many of those functions require different library function. Now, I want to know what is a better practice - to import all the libraries in the module, or import the libraries within the functions? Is there any difference in terms of performance?
Example code
my_module.py
from math import exp
from numpy import mean,random
def logit(x):
return exp(x)/(1+exp(x))
def sample_mean(mu,sigma,size):
return mean(random.normal(mu,sigma,size))
Or
def logit(x):
from math import exp
return exp(x)/(1+exp(x))
def sample_mean(mu,sigma,size):
from numpy import mean,random
return mean(random.normal(mu,sigma,size))
P.S.
This is just a sample code to explain my dilemma. Don't tell me that there are ready made functions to use instead of these user-defined functions. I already know that