Home > Net >  How do I print in index of my output for a numpy arange?
How do I print in index of my output for a numpy arange?

Time:04-28

def x(t,A,ω,γ,ϕ):
    return A*np.cos(np.sqrt(ω**2-(γ/2)**2)*t ϕ)*np.exp(-γ*t/2)

a=x(np.arange(0,10,0.01),1,1,1,-np.pi/2)

b=[np.max(np.abs(a)), ]

print(b)

#This was the output [0.47310347814336845]

I want to know how can I get the index of the np.arange that this output belongs to?

CodePudding user response:

You can use np.argmax():

np.argmax(np.abs(a))

This outputs:

121
  • Related