AttributeError:模块“时间"在Jupyter Notebook中没有属性"clock" [英] AttributeError: module 'time' has no attribute 'clock in jupyter notebook

查看:139
本文介绍了AttributeError:模块“时间"在Jupyter Notebook中没有属性"clock"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在juppyter笔记本中出现错误

in juppyter notebook getting error as

AttributeError跟踪(最近一次呼叫最近)t0 = time.clock()#启动计时器以查找仿真时间

AttributeError Traceback (most recent call last) t0=time.clock() # start timer for finding simulation time

AttributeError:模块时间"没有属性时钟"获取以下代码

AttributeError: module 'time' has no attribute 'clock' for following code

import numpy as np
import matplotlib.pyplot as plt
import time
t0=time.clock() # start timer for finding simulation time

# Problem parameters
k1=50 # cart 1 spring constant (N/m)
k2=50 # cart 2 spring constant (N/m)
b1=3 # cart 1 viscous damping coefficient (kg/s)
b2=3 # cart 2 viscous damping coefficient (kg/s)
m1=5 # cart 1 mass (kg)
m2=5 # cart 2 mass (kg)
x10=1 # cart 1 initial position (m)
x20=-1 # cart 2 initial position (m)
v10=0 # cart 1 initial velocity (m/s)
v20=0 # cart 2 initial velocity (m/s)

# Set time step stuff
simTime=10 # simulation time (s)
tStep=0.001 # simulation time step
iterations=int(simTime/tStep) # total number of iterations
t=np.arange(0,iterations)

# Pre-allocate variables for speed and add initial conditions
x1=np.zeros((iterations,1))
x1[0,:]=x10
x2=np.zeros((iterations,1))
x2[0,:]=x20
v1=np.zeros((iterations,1))
v1[0,:]=v10
v2=np.zeros((iterations,1))
v2[0,:]=v20
a1=np.zeros((iterations,1))
a1[0,:]=-(b1*v10-b2*(v20-v10)+k1*x10-k2*(x20-x10))/m1
a2=np.zeros((iterations,1))
a2[0,:]=-(b2*(v20-v10)+k2*(x20-x10))/m2

# Solve the ODE's with Euler's Method
for n in range(1,iterations):
  x1[n,:]=x1[n-1,:]+v1[n-1,:]*tStep # cart 1 position
  x2[n,:]=x2[n-1,:]+v2[n-1,:]*tStep # cart 2 position
  v1[n,:]=v1[n-1,:]+a1[n-1,:]*tStep # cart 1 velocity
  v2[n,:]=v2[n-1,:]+a2[n-1,:]*tStep # cart 2 velocity
  # Find cart accelerations
  a1[n,:]=-(b1*v1[n,:]-b2*(v2[n,:]-v1[n,:])+k1*x1[n,:]-k2*(x2[n,:]-x1[n,:]))/m1
  a2[n,:]=-(b2*(v2[n,:]-v1[n,:])+k2*(x2[n,:]-x1[n,:]))/m2

推荐答案

您是否正在使用> 3.7的Python版本? time.clock 函数已从Python 3.8版本中删除.删除通知包含在时间文档(适用于Python 3.7)中.

Are you using a Python version >3.7? The time.clock function has been removed as of version Python 3.8. The removal notice was included in the time documentation for Python 3.7.

这篇关于AttributeError:模块“时间"在Jupyter Notebook中没有属性"clock"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆