Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating step function
#2
Occasional numpy user here, the following example may help
>>> import numpy as np
>>> t = np.linspace(0, 12, 30)
>>> t
array([ 0.        ,  0.4137931 ,  0.82758621,  1.24137931,  1.65517241,
        2.06896552,  2.48275862,  2.89655172,  3.31034483,  3.72413793,
        4.13793103,  4.55172414,  4.96551724,  5.37931034,  5.79310345,
        6.20689655,  6.62068966,  7.03448276,  7.44827586,  7.86206897,
        8.27586207,  8.68965517,  9.10344828,  9.51724138,  9.93103448,
       10.34482759, 10.75862069, 11.17241379, 11.5862069 , 12.        ])
>>> np.where(np.logical_and(0 < t, t < 1), 150.0, 0.0) + np.where(np.logical_and(10.0 < t, t < 11.0), 50.0, 0.0)
array([  0., 150., 150.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,
         0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,
         0.,   0.,   0.,  50.,  50.,   0.,   0.,   0.])
erdemath likes this post
Reply


Messages In This Thread
Creating step function - by erdemath - Jul-25-2021, 06:33 PM
RE: Creating step function - by Gribouillis - Jul-25-2021, 07:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Trouble with creating a looping function in python 2.7 (complex) Afterdarkreader 3 3,162 Dec-12-2017, 06:56 PM
Last Post: Afterdarkreader

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020