Pass in a float to np.linspace

Viewed 3675

I have the following code:

dt     = .001   # simulation time step (seconds)
T      = 1.0    # total time to simulate (seconds)
time   = np.linspace(dt,T,dt/T)

But I am getting the following error:

TypeError: 'float' object cannot be interpreted as an integer
time   = np.linspace(dt,T,dt) # vector of timepoints we will simulate

I am writing the code in a PyCharm IDE using a Conda virtual environment to provide a little more context. Thank in advance!

2 Answers

I agree with Dwight in the comments, but I thought I could tell you anyway, just to give you another option, that numpy.arange(start, stop, step) may be also useful to you, and should do the same trick.

What you are trying to do actually corresponds to np.arange.

time = np.arange(dt, T, dt)

To include the T time you will need to change the stop boundary to T + dt.

Related