# numpy.log() in Python

## numpy.log() in Python

The numpy.log() is a mathematical function that helps user to calculate Natural logarithm of x where x belongs to all the input array elements.
Natural logarithm log is the inverse of the exp(), so that log(exp(x)) = x. The natural logarithm is log in base e.

Syntax :numpy.log(x[, out] = ufunc ‘log1p’)
Parameters :

array : [array_like] Input array or object.
out : [ndarray, optional] Output array with same dimensions as Input array, placed with result.

Return :
An array with Natural logarithmic value of x; where x belongs to all elements of input array.

Code #1 : Working

 `# Python program explaining` `# log() function` `import` `numpy as np` ` ` `in_array ``=` `[``1``, ``3``, ``5``, ``2``*``*``8``]` `print` `(``"Input array : "``, in_array)` ` ` `out_array ``=` `np.log(in_array)` `print` `(``"Output array : "``, out_array)` ` ` ` ` `print``(``"\nnp.log(4**4) : "``, np.log(``4``*``*``4``))` `print``(``"np.log(2**8) : "``, np.log(``2``*``*``8``))`

Output :

```Input array :  [1, 3, 5, 256]
Output array :  [ 0.          1.09861229  1.60943791  5.54517744]

np.log(4**4) :  5.54517744448
np.log(2**8) :  5.54517744448
```

Code #2 : Graphical representation

 `# Python program showing` `# Graphical representation  ` `# of log() function` `import` `numpy as np` `import` `matplotlib.pyplot as plt` ` ` `in_array ``=` `[``1``, ``1.2``, ``1.4``, ``1.6``, ``1.8``, ``2``]` `out_array ``=` `np.log(in_array)` ` ` `print` `(``"out_array : "``, out_array)` ` ` `plt.plot(in_array, in_array, ` `         ``color ``=` `'blue'``, marker ``=` `"*"``)` ` ` `# red for numpy.log()` `plt.plot(out_array, in_array, ` `         ``color ``=` `'red'``, marker ``=` `"o"``)` `          ` `plt.title(``"numpy.log()"``)` `plt.xlabel(``"out_array"``)` `plt.ylabel(``"in_array"``)` `plt.show() `

Output :

```out_array :  [ 0.          0.18232156  0.33647224  0.47000363  0.58778666  0.69314718]
```

Last Updated on November 1, 2021 by admin

## Calculate the Euclidean distance using NumPyCalculate the Euclidean distance using NumPy

Calculate the Euclidean distance using NumPy In simple terms, Euclidean distance is the shortest between

## numpy.multiply() in Pythonnumpy.multiply() in Python

numpy.multiply() in Python numpy.multiply() function is used when we want to compute the multiplication of two

## numpy.percentile() in pythonnumpy.percentile() in python

numpy.percentile() in python numpy.percentile()function used to compute the nth percentile of the given data (array

## Numpy Meshgrid functionNumpy Meshgrid function

Numpy Meshgrid function The numpy.meshgrid function is used to create a rectangular grid out of

## numpy.argmax() in Pythonnumpy.argmax() in Python

numpy.argmax() in Python The numpy.argmax() function returns indices of the max element of the array in a

## Numpy cheatsheetNumpy cheatsheet

This Numpy cheatsheet is a complete guide for learning Numpy, suitable for beginners to advanced

## Change data type of given numpy arrayChange data type of given numpy array

Change data type of given numpy array In this post, we are going to see

## numpy.reshape() in Pythonnumpy.reshape() in Python

numpy.reshape() in Python The numpy.reshape() function shapes an array without changing the data of the array. Syntax: