Change language

# Python | Tensorflow exp () method

The `tensorflow.math ` module provides support for many basic mathematical operations. The ` tf.exp () ` [alias ` tf.math.exp `] function provides support for the exponential function in Tensorflow. Expected to be input as complex numbers in the form or floating point. Input type — tensor, and if the input contains more than one element, an element-wise exponential value is calculated, ,

Syntax : tf.exp (x, name = None) or tf.math.exp (x, name = None)

Parameters :
x : A Tensor of type bfloat16, half, float32, float64, complex64 or complex128.
name (optional): The name for the operation.

Return type : A Tensor with the same size and type as that of x.

Code # 1:

 ` # Import Tensorflow library ` ` import ` ` tensorflow as tf ` ` `  ` # Constant vector of size 5 ` ` a ` ` = ` ` tf.constant ([` ` - ` ` 0.5 ` `, ` ` - ` ` 0.1 ` `, ` ` 0 ` `, ` ` 0.1 ` `, ` ` 0.5 ` `], dtype ` ` = ` ` tf.float32) `   ` # Applying the exp function and ` ` # saving the result to & # 39; b & # 39; ` ` b ` ` = ` ` tf.exp (a, name ` ` = ` ` ’exp’ ` `) ` ` `  ` # Initiate a session Tensorflow ` ` with tf.Session () as sess: ` ` print ` ` (` ` ’Input type:’ ` `, a) ` ` print ` ` ( ` ` ’Input:’ ` `, sess.run (a)) ` ` print ` ` (` ` ’Return type:’ ` `, b) ` ` print ` ` (` ` ’Output:’ ` `, sess.run (b)) `

Exit:

` Input type: Tensor ("Const: 0", shape = (5,), dtype = float32) Input: [-0.5 -0.1 0. 0.1 0.5] Return type: Tensor ("exp: 0", shape = (5,), dtype = float32) Output: [0.60653067 0.9048374 1.1.105171 1.6487212] `

Code # 2: Rendering

 ` # Import Tensorflow library ` ` import ` ` tensorflow as tf `   ` # Import NumPy library ` ` import ` ` numpy as np ` ` `  ` # Import the matplotlib.pylot function ` ` import ` ` matplotlib.pyplot as plt `   ` # Vector size 21 with values ​​from -10 to 10 ` ` a ` ` = < / code> np.linspace ( - 10 , 10 , 21 ) ``   # Applying an exponential function and # save the result to & # 39; b & # 39; b = tf.exp (a, name = ’ exp’ )   # Initiating a Tensorflow session with tf.Session () as sess: print ( ’ Input: ’ , a) print ( ’Output:’ , sess.run (b)) plt.plot (a, sess.run (b), color = ’red’ , marker = " o " )  plt.title ( "tensorflow.abs" )  plt.xlabel ( "X" )  plt.ylabel ( "Y" )       plt.show () `

Output :

` Input: [-10. -nine. -eight. -7. -6. -five. -four. -3. -2. -one. 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10.] Output: [4.53999298e-05 1.23409804e-04 3.35462628e-04 9.11881966e-04 2.47875218e-03 6.73794700e-03 1.83156389e-02 4.97870684e-02 1.35335283e-01 3.67879441e-01 1.00000000e + 00 2.71828183e + 00 7.38905610e + 00 2.00855369e + 01 5.45981500e + 01 1.48413159e + 02 4.03428793e + 02 1.0966933167 +03 8.10308393e + 03 2.20264658e + 04] `

## Shop

Learn programming in R: courses

\$FREE

Best Python online courses for 2022

\$FREE

Best laptop for Fortnite

\$399+

Best laptop for Excel

\$

Best laptop for Solidworks

\$399+

Best laptop for Roblox

\$399+

Best computer for crypto mining

\$499+

Best laptop for Sims 4

\$

Latest questions

PythonStackOverflow

Common xlabel/ylabel for matplotlib subplots

PythonStackOverflow

Check if one list is a subset of another in Python

PythonStackOverflow

How to specify multiple return types using type-hints

PythonStackOverflow

Printing words vertically in Python

PythonStackOverflow

Python Extract words from a given string

PythonStackOverflow

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

PythonStackOverflow

Python os.path.join () method

PythonStackOverflow

Flake8: Ignore specific warning for entire file

## Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

How to specify multiple return types using type-hints

Printing words vertically in Python

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries