Skip to content
Advertisement

Using only numpy, is there a way to create a square wave?

I have tried using masks and making lists like x = [0,0.5,0.51,1,1.01], y = [1,1,-1,-1,1] works ofcourse, but is quite tedious and not as nice as i want to make a square wave from x = 0 to 5.

Advertisement

Answer

You could write a little function like this to populate x and y

JavaScript

Output

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement