Issue
I want to plot this exponential function:
T = np.random.exponential(3,50)
as a function of time (Minutes 1-15) t = np.arange(0,15,1)
.
I get: x and y must have same first dimension...
Could you explain how it can be done properly? I'd like to understand.
Solution
T
is not a function, it's an array. You must ensure that t
and T
have the same shape.
You should pass a size
that is the same as the length of t
to np.random.exponential
:
import numpy as np
import matplotlib.pyplot as plt
t = np.arange(0, 15, 1)
T = np.random.exponential(3, size=len(t))
plt.plot(t, T)
Note that since T
is random, there is no direct relationship between t
and T
.
Output:
Conversely, to scape t
from T
's shape, use np.linspace
:
T = np.random.exponential(3, 50)
t = np.linspace(0, 15, num=len(T))
plt.plot(t, T)
Output:
Answered By - mozway
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.