Skip to content

Base of np.log1p #14969

@gokceneraslan

Description

@gokceneraslan

np.log1p is a great function but not having alternatives with different bases (like log2 and log10) is very limiting. I wonder if it'd be possible to add other functions like log2_1p and log10_1p (and possibly exp2_m1 and exp10_m1).

I played around with some numba-based solutions such as this one based on the original implementation in numpy:

@vectorize([float64(int32),
            float64(int64),
            float32(float32),
            float64(float64)])
def log10_1p(x):
    if np.isinf(x) and x > 0: 
        return x
    
    u = 1. + x
    d = u - 1.
    
    if d == 0:
        return x

    return np.log10(u) * x / d

it seems to be working well (see https://nbviewer.ipython.org/gist/gokceneraslan/2744cfeda702fb9b9e48d0216427372c for some results) but having a numpy-native function would be really great.

PS: Can anybody explain why there is a * x / d in the end? Maybe @khinsen can shed some light.

Metadata

Metadata

Assignees

No one assigned

    Labels

    33 - QuestionQuestion about NumPy usage or development57 - Close?Issues which may be closable unless discussion continued

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions