Python Numpy.log() - 自然對數

Jinku Hu 2023年1月30日 2020年6月17日
  1. numpy.log() 語法
  2. 示例程式碼:numpy.log()
  3. 示例程式碼: numpy.log2() - 基數為 2 的對數
  4. 示例程式碼: numpy.log10() - 對數基數為 10
Python Numpy.log() - 自然對數

numpy.log() 函式計算給定陣列中每個元素的自然對數

numpy 自然對數

numpy.log() 語法

numpy.log(arr) 

引數

arr 輸入陣列

返回值

它返回輸入陣列中每個元素的自然對數。

示例程式碼:numpy.log()

import numpy as np

arr = [1, np.e, np.e**2, np.e**3]
print(np.log(arr))

輸出:

[0. 1. 2. 3.]

示例程式碼: numpy.log2() - 基數為 2 的對數

numpy.log2()numpy.log() 類似,但基數是 2 而不是 e

numpy.log2() 與 numpy.log() 相似,但基數是 2 而不是 e

import numpy as np

arr = [1, 2, np.e, 4]
print(np.log2(arr))

輸出:

[0. 1. 1.44269504 2.]

示例程式碼: numpy.log10() - 對數基數為 10

numpy.log10() 類似於 numpy.log(),但基數是 10 而不是 e

numpy.log10() 類似於 numpy.log(),但基數是 10 而不是 e

import numpy as np

arr = [1, np.e, 10, 100]
print(np.log10(arr))

輸出:

[0. 0.43429448 1. 2.]
Author: Jinku Hu
Jinku Hu avatar Jinku Hu avatar

Founder of DelftStack.com. Jinku has worked in the robotics and automotive industries for over 8 years. He sharpened his coding skills when he needed to do the automatic testing, data collection from remote servers and report creation from the endurance test. He is from an electrical/electronics engineering background but has expanded his interest to embedded electronics, embedded programming and front-/back-end programming.

LinkedIn