Python:NumPy .log()

Anonymous contributor's avatar
Anonymous contributor
Published May 25, 2022Updated Nov 2, 2024
Contribute to Docs

The .log() function returns an element-wise natural logarithm of an array.

  • Machine Learning Data Scientists solve problems at scale, make predictions, find patterns, and more! They use Python, SQL, and algorithms.
    • Includes 27 Courses
    • With Professional Certification
    • Beginner Friendly.
      95 hours
  • Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
    • With Certificate
    • Beginner Friendly.
      24 hours

Syntax

numpy.log(array)

.log() returns an ndarray with each element as the natural logarithm of the corresponding element in array.

Example

The following example creates a ndarray and applies .log() to it:

import numpy as np
nd = np.array([[1,2.71828],[2.71828,1]])
print(nd)
print(np.log(nd))

This produces the following output:

[[1. 2.71828]
[2.71828 1. ]]
[[0. 0.99999933]
[0.99999933 0. ]]

Codebyte Example

The following codebyte creates different arrays and demonstrates applying np.log() to each array, calculating the natural logarithm of all elements:

Code
Output
Loading...

All contributors

Contribute to Docs

Learn Python:NumPy on Codecademy

  • Machine Learning Data Scientists solve problems at scale, make predictions, find patterns, and more! They use Python, SQL, and algorithms.
    • Includes 27 Courses
    • With Professional Certification
    • Beginner Friendly.
      95 hours
  • Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
    • With Certificate
    • Beginner Friendly.
      24 hours