Algorithm to map an interval to a smaller interval

前端 未结 6 2057
生来不讨喜
生来不讨喜 2021-02-02 11:50

I tried searching, but due to the nature of my question, I was unable to find something satisfactory.

My problem is the following: I am trying to map numbers ranging fro

6条回答
  •  爱一瞬间的悲伤
    2021-02-02 12:43

    An answer using Numpy from Python:

    import numpy as np  
    
    # [A, B]: old interval
    # [a, b] new interval
    new_value = np.interp(old_value, [A, B], [a, b])
    print(new_value)
    

提交回复
热议问题