Search code examples
pythonexponential

Can I apply exp function directly on a list or matrix?


Can I raise a list to the power of e Like

np.exp(L)

instead of using a for loop for every single element? And does it apply to Arrays and Matrices too?


Solution

  • looks like yes, yes you can

    >>> import numpy as np
    >>> L=np.array([1,2,3,4,5])
    >>> np.exp(L)
    array([  2.71828183,   7.3890561 ,  20.08553692,  54.59815003,
           148.4131591 ])
    

    even if it's just a plain list and not a numpy array:

    >>> L = [1,2,3,4,5]
    >>> np.exp(L)
    array([  2.71828183,   7.3890561 ,  20.08553692,  54.59815003,
           148.4131591 ])
    >>>