Why is the curve set up a bite function schedule



  • I'm trying to build a triangular function as a part of a bite function, but somehow it doesn't turn right on the plot.

    import numpy as np
    import matplotlib.pyplot as plt
    

    def s_similar(x, a, b, c):
    if x <= a:
    return 0
    elif x > a and x <= b:
    return (x - a)/(b - a)
    elif x > b and x <= c:
    return -(x - b)/(c - b) + 1
    else:
    return 0

    x = np.arange(0, 100, 1)
    g = np.vectorize(s_similar)
    y = g(x, 20, 50, 80)

    plt.plot(x, y)
    plt.show()

    введите сюда описание изображения



  • 'Cause you're running a whole number, and all these divisions give a result of PP 1, that's 0.

    Use this code:

    g = np.vectorize(s_similar, otypes=[np.float])
    

    and everything will be fine.

    It's a warning. float (sighs)DeprecationWarning: 'np.float' is a deprecated alias for the builtin 'float'.That's why use this code better.

    g = np.vectorize(s_similar, otypes=[np.float64])
    

    He doesn't give any warnings.

    введите сюда описание изображения


Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2