我已经安装了 Simpy,并且使用 Python 3.5。我有同样的错误:
>>> env = simpy.Environment()
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
env = simpy.Environment()
AttributeError: module 'simpy' has no attribute 'Environment'
Run Code Online (Sandbox Code Playgroud)
它允许我导入 simpy,但是当我这样做时,env = simpy.Environment()它会打印此错误。
我尝试卸载它,重新安装,在终端中使用,在Python的IDLE中,在其他IDLE中使用......
整个代码是(来自教程):
>>> def car(env):
... while True:
... print('Start parking at %d' % env.now)
... parking_duration = 5
... yield env.timeout(parking_duration)
...
... print('Start driving at %d' % env.now)
... trip_duration = 2
... yield env.timeout(trip_duration)
>>> import simpy
>>> env = simpy.Environment()
Run Code Online (Sandbox Code Playgroud)
然后弹出错误。 …
我想绘制一个图形xticks,例如,从50到100.
到目前为止我尝试过的:
data_to_plot = data[-90:] # 90 datapoints
# Create figure
fig = plt.figure()
ax = fig.add_subplot(111)
# Plot the value
ax.plot(data_to_plot/S)
# Set the ticks
x_ticks = np.arange(50, 140)
ax.set_xticks(x_ticks)
# Limits
plt.ylim(0, 1)
# Naming
plt.title("Cooperation")
plt.xlabel("Round")
plt.ylabel("Value")
plt.show()
Run Code Online (Sandbox Code Playgroud)
我得到的是这个数字:
而不是xticks从50up to开始的数字,即xticks 中标签140的列表 [50, 60, 70, ..., 130, 140] 。
使用: Python 3、Matplotlib 3.0.2、MacOS 10.13。
我正在创建一个(简单的)基于代理的模型来学习 Scala 和函数式编程。
我已经在 Python 中创建了它,所以我的想法是按照已经存在的想法对其进行编码,但是我在开始时遇到了一个问题:
我有一个类描述模型中的一个代理,另一个类描述它所生活的社会。社会由 N 个代理组成,其中 N 是一个整数。在 Python 中,我会做一个列表理解来存储类的所有实例,但我如何在 Scala 中做到这一点?有没有比使用以下代码更好的方法:
import agent.Agent
class Society([omitted-for-brevity]){
val tmp_agents = List()
for(i <- 1 to puntos){
val tmp_agent = new Agent(pos_X = 0, name="Agent "+i)
tmp_agents :+ tmp_agent
}
Run Code Online (Sandbox Code Playgroud)
val tmp_agentfor 循环中的值不应该是 var 吗?或者,如果 Agent 类有var参数作为输入,它是否有效?tmp_agents如果只有其中的对象要更改“内部”值,该列表是否应该是 val?附加到 val 可以吗?