Berikut contoh kode highlighting
import numpy as np
import matplotlib.pyplot as plt
# untuk menggunakan numpy.piecewise harus dibuat fungsi biasa dalam python.
def g(x):
return 2*(1-x) # untuk 0 < x < 1
def h(x):
return 0 # untuk selainnya
# Evaluasi fungsi g dan h secara bersamaan menggunakan numpy.piecewise
x = np.linspace(-5,5,1000)
y = np.piecewise(x,[(x>0)*(x<1 x="">=1)],[g,h])
# plot
plt.figure(figsize =(8,6))
plt.plot(x,y)
1>
Bandingkan dengan hasil gist dari github
Mana yang lebih bagus?