Hướng dẫn inverse log transformation python


In this video we will continue with point operations - Log and Inverse Log transformation on images. The log transformation can be defined by this formula = c*log(1+r) where s and r are the pixel values of the output and the input image and c is a constant.

Log and Inverse Log transformation on Image in Python


y=np.log10(train_set["SalePrice"])

how do i find inverse of this ?? I want it to return back to the original value and not the scaled value

hoefling

51.3k10 gold badges131 silver badges168 bronze badges

asked Aug 3, 2018 at 9:21

2

Hope the above answers were helpful, in case you or anyone want the inverse for log10 (base 10) and log (natural)

# Logarithm and back to normal value
y = np.log10(train_set["SalePrice"])
train_set["SalePrice"] = 10 ** y

# Natural log and back to normal value using built-in numpy exp() function
y = np.log(train_set["SalePrice"])
train_set["SalePrice"] = np.exp(y)

answered Mar 23, 2020 at 13:44

Hướng dẫn inverse log transformation python

If you want to obtain the original value then you can do:

z = 10**y

answered Aug 3, 2018 at 9:25

Jacques UngJacques Ung

1492 silver badges6 bronze badges

y = np.log10(train_set["SalePrice"])

return back to the original value all of array elements

Z = np.array(10**y)

answered Jun 1, 2020 at 14:36

A logarithm of a given number n is the exponent to which another number which is been fixed, the base b, must be raised, to produce that number n. In layman terms the logarithm counts the number of occurrences of the same factor in repeated multiplication.  A logarithmic function is represented as:

f(x) = log b (x)

When the base b of the logarithm equals 10, we generally don’t mention it, i.e. f(x) = log (x). The inverse of a log or exponential function is given by :

In general case,  

y = log b (x)  ⇐⇒  b y = x

For natural log: 

y = ln (x)    ⇐⇒   e y = x

let us look at some examples for better understanding:

Example 1: if y = ln (544) = 6.298949

                       antilog ( y ) = e y = 544

Example 2: if y = log (544) = 2.735598

                       antilog ( y ) = 10 y = 544

An inverse log transformation in the R programming language can be exp(x) and expm1(x) functions. exp( ) function simply computes the exponential function, whereas the expm1( ) function computes exp(x) – 1 accurately also for |x| << 1. Here x must be a numeric or complex vector and base must be positive.

Method 1: Using exp()

Syntax:

 exp ( x )

Where, x is a numeric value.

Example:

R

exp (100) 

exp (9867528) 

exp (0)

exp (1.7865)

Output:

[1] 2.688117e+43      # exp (100)

[1] Inf               # exp (9867528)

[1] 1                 # exp (0)

[1] 5.968526          # exp (1.7865)

For bigger numbers, it generally returns “Inf” which means infinity.

Method 2: Using expm1()

Syntax:

 expm1 ( x ) = exp (x) – 1

Where, x is a numeric value.

Example:

R

expm1 (100)

expm1 (9867528)

expm1 (0)

expm1 (1.7865)

Output:

[1] 2.688117e+43      # expm1 (100)

[1] Inf               # expm1 (9867528)

[1] 0                 # expm1 (0)

[1] 4.968526          # expm1 (1.7865)

For large numeric values exp( ) and expm1( ) functions return the same values.

Example :

R

y = log(544, base = exp(1))

print(y)

antilog_y1 = exp (y)

print(antilog_y1)

antilog_y2 = expm1 (y)

print(antilog_y2)

Output:

[1] 6.298949               # print(y)

[1] 544                    # print(antilog_y1)

[1] 543                    # print(antilog_y2)