I would like to plot the following piecewise function in Python using Matplotlib, from 0 to 5.
f(x) = 1, x != 2; f(x) = 0, x = 2
In Python...
The problem is that the function f does not take an array as input but a single numer. You can:
f
plt.plot(x, map(f, x))
The map function takes a function f, an array x and returns another array where the function f is applied to each element of the array.
map
x