我仍然是一个新手Scala程序员,很抱歉,如果这个问题可能看起来很幼稚,但我搜索了一段时间后发现没有解决方案.我使用的是Scala 2.8,我将PXGivenZ类定义为:
class PXGivenZ (val x:Int, val z:Seq[Int], val values: Map[Seq[Int], Map[Int, Double]] ){...}
Run Code Online (Sandbox Code Playgroud)
当我尝试将该类的元素实例化为另一个程序块时,如下所示:
// x is an Int
// z is a LinkedList of Int
...
var zMap = new HashMap[Seq[Int], HashMap[Int, Double]]
...
val pxgivenz = new PXGivenZ(x, z, zMap)
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
found : scala.collection.mutable.HashMap[Seq[Int],scala.collection.mutable.HashMap[Int,Double]]
required: Map[Seq[Int],Map[Int,Double]]
val pxgivenz = new PXGivenZ(x, z, zMap)
^
Run Code Online (Sandbox Code Playgroud)
显然我没有得到:Map [Seq [Int],Map [Int,Double]]与HashMap [Seq [Int],HashMap [Int,Double]]的不同之处是什么?或者"可变"课程出了什么问题?
在此先感谢能帮助我的人!
我是SymPy和Python的新手,我目前正在使用Python 2.7和SymPy 0.7.5,其目标是:a)从文本文件中读取微分方程组b)解决系统问题
我已经读过这个问题和另外一个问题了,它们几乎就是我要找的,但我还有一个额外的问题:我事先并不知道方程组的形式,所以我无法在def里面创建相应的函数脚本,如本例所示.整个过程必须在运行时进行管理.
所以,这里是我的代码的一些片段.假设我有一个包含以下内容的文本文件system.txt:
dx/dt = 0.0387*x - 0.0005*x*y
dy/dt = 0.0036*x*y - 0.1898*y
Run Code Online (Sandbox Code Playgroud)
我所做的是:
# imports
import sympy
import scipy
import re as regex
# define all symbols I am going to use
x = sympy.Symbol('x')
y = sympy.Symbol('y')
t = sympy.Symbol('t')
# read the file
systemOfEquations = []
with open("system.txt", "r") as fp :
for line in fp :
pattern = regex.compile(r'.+?\s+=\s+(.+?)$')
expressionString = regex.search(pattern, …Run Code Online (Sandbox Code Playgroud) 我正在使用 matplotlib 绘制条形图,当我尝试访问标签(在 X 轴和 Y 轴上)以更改它们时遇到问题。特别是,这段代码:
fig = plot.figure(figsize=(16,12), dpi=(300))
ax1 = fig.add_subplot(111)
ax1.set_ylabel("simulated quantity")
ax1.set_xlabel("simulated peptides - from most to least abundant")
# create the bars, and set a different color for the bars referring to experimental peptides
barlist = ax1.bar( numpy.arange(len(quantities)), [numpy.log10(x) for x in quantities] )
for index, peptide in enumerate(peptides) :
if peptide in experimentalPeptidesP or peptide in experimentalPeptidesUP :
barlist[index].set_color('b')
labelsY = ax1.get_yticklabels(which='both')
print "These are the label objects on the Y axis:", labelsY …Run Code Online (Sandbox Code Playgroud)