你如何搜索一个关键HashMap?在此程序中,当用户输入密钥时,代码应安排在哈希映射中搜索相应的值,然后将其打印出来.
请告诉我为什么它不起作用.
import java.util.HashMap;
import java.util.; import java.lang.;
public class Hashmapdemo
{
public static void main(String args[])
{
String value;
HashMap hashMap = new HashMap();
hashMap.put( new Integer(1),"January" );
hashMap.put( new Integer(2) ,"February" );
hashMap.put( new Integer(3) ,"March" );
hashMap.put( new Integer(4) ,"April" );
hashMap.put( new Integer(5) ,"May" );
hashMap.put( new Integer(6) ,"June" );
hashMap.put( new Integer(7) ,"July" );
hashMap.put( new Integer(8),"August" );
hashMap.put( new Integer(9) ,"September");
hashMap.put( new Integer(10),"October" );
hashMap.put( new Integer(11),"November" );
hashMap.put( new Integer(12),"December" …Run Code Online (Sandbox Code Playgroud) 我一夜之间训练了一个keras模型,准确度达到75%,我现在很高兴.它有60,000个样本,每个样本的序列长度为700,词汇量为30.每个epoch在我的gpu上大约需要10分钟.因此,这是60,000/600秒,大约每秒100个样本,并且必须包括反向传播.所以我保存了我的hdf5文件并再次加载.
<code>#Model:
model = Sequential()
model.add(LSTM(128, input_shape=(X.shape[1], X.shap[2]), return_sequences=True)) model.add(Dropout(0.25)) model.add(LSTM(64)) model.add(Dropout(0.25)) model.add(Dense(y.shape[1], activation='softmax'))
</code>
Run Code Online (Sandbox Code Playgroud)
然后当我做出我的预测时,每次预测花费的时间比1秒多,比训练慢100倍.预测很好,我看了小批量,我可以使用它们.问题是我需要10万多个.每次预测10ms秒可以工作,1秒不会.
谁能提出加速Keras预测的方法?
我想看看具有特定参数的正态分布是否适合数据集。然而 qqplot 似乎并没有像预期的那样工作。下面的小例子展示了这一点:
import numpy as np
import statsmodels.api as sm
import pylab
test = np.random.normal(20,5, 1000)
sm.qqplot(test, loc = 20, scale = 5 , line='45')
pylab.show()
Run Code Online (Sandbox Code Playgroud)
正如人们所看到的,我期望这些点位于斜率 = 1 的线周围,但它给出了下图:
谁能解释一下为什么会发生这种情况?
MVC'架构'.我想要一种方便的方法来指定纸牌游戏的规则,包括诸如手或技巧,得分,使用牌组或包中的哪些牌等等.有没有人知道这样的事情,最好是在Javascript中?
谢谢你的指导.
javascript python model-view-controller game-engine playing-cards
如何从 SymPy 给我的微分方程的解中计算常数 C1 和 C2?有初始条件 f(0)=0 和 f(pi/2)=3。
>>> from sympy import *
>>> f = Function('f')
>>> x = Symbol('x')
>>> dsolve(f(x).diff(x,2)+f(x),f(x))
f(x) == C1*sin(x) + C2*cos(x)
Run Code Online (Sandbox Code Playgroud)
我尝试了一些ics东西,但它不起作用。例子:
>>> dsolve(f(x).diff(x,2)+f(x),f(x), ics={f(0):0, f(pi/2):3})
f(x) == C1*sin(x) + C2*cos(x)
Run Code Online (Sandbox Code Playgroud)
顺便说一下:C2 = 0 和 C1 = 3。
我遇到了 xpath 表达式的问题。请有人帮助我吗?
所以我的 xpath 是 -".//td[starts-with(text(), 'IMT - Office Admin:')]"
DOM:
<td>
<input type="checkbox" name="partyEditF:j_id698:6:j_id700">
IMT - Office Admin: Ability to edit everything within your office including the office's information and listings
</td>
Run Code Online (Sandbox Code Playgroud) 我知道python执行矩阵乘法的能力.不幸的是我不知道如何抽象地这样做?所以不是一定数字,而是变量.
例:
M = ( 1 0 ) * ( 1 d )
( a c ) ( 0 1 )
Run Code Online (Sandbox Code Playgroud)
有没有办法定义a,c和d,以便矩阵乘法给我
( 1 d )
( a a*d + c )
Run Code Online (Sandbox Code Playgroud)
?
我有以下数据框架
ipdb> csv_data
country sale date trans_factor
0 India 403171 12/01/2012 1
1 Bhutan 394096 12/01/2012 2
2 Nepal super 12/01/2012 3
3 madhya 355883 12/01/2012 4
4 sudan man 12/01/2012 5
Run Code Online (Sandbox Code Playgroud)
截至目前我正在使用下面的代码在表中插入数据,如果表已经存在,则删除它并创建新表
csv_file_path = data_mapping_record.csv_file_path
original_csv_header = pandas.read_csv(csv_file_path).columns.tolist()
csv_data = pandas.read_csv(csv_file_path, skiprows=[0], names=original_csv_header, infer_datetime_format=True)
table_name = data_mapping_record.csv_file_path.split('/')[-1].split('.')[0]
engine = create_engine(
'postgresql://username:password@localhost:5432/pandas_data')
# Delete table if already exits
engine.execute("""DROP TABLE IF EXISTS "%s" """ % (table_name))
# Write the pandas dataframe to database using sqlalchemy and pands.to_sql
csv_data_frame.to_sql(table_name, engine, chunksize=1000) …Run Code Online (Sandbox Code Playgroud) 我怎样才能让相同的图例出现在 2 个子图上,并使其扩展到 2 个子图上。有人知道吗,如果我必须单独精确每个子图的 y 标签(如果它是相同的)(该图用于一篇科学论文) ?我知道后一个问题与计算无关,但如果有人知道答案,我将不胜感激。
对于图例的放置,我使用:
ax[0].legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3,
ncol= 4, mode="expand", borderaxespad=0)
Run Code Online (Sandbox Code Playgroud)
我有一个s="gh3wef2geh4ht". 我如何s="gh333wef22geh4444ht"通过使用子接收。我试过这个正则表达式。我做错了什么?
s=re.sub(r"(\d)",r"\1{\1}",s)
Run Code Online (Sandbox Code Playgroud) 我写了这个函数来找到一个阶乘数
fact <- function(n) {
if (n < 0){
cat ("Sorry, factorial does not exist for negative numbers", "\n")
} else if (n == 0){
cat ("The factorial of 0 is 1", "\n")
} else {
results = 1
for (i in 1:n){
results = results * i
}
cat(paste("The factorial of", n ,"is", results, "\n"))
}
}
Run Code Online (Sandbox Code Playgroud)
现在我想在R中实现Memoization.我在R上有基本思想并尝试使用它们.但我不确定这是前进的方向.你能否也请详细说明这个话题.预先感谢.记忆因素
fact_tbl <- c(0, 1, rep(NA, 100))
fact_mem <- function(n){
stopifnot(n > 0)
if(!is.na(fib_tbl[n])){
fib_tbl[n]
} else {
fact_tbl[n-1] <<- fac_mem(n-1) * …Run Code Online (Sandbox Code Playgroud) import math
from scipy.optimize import fsolve
def sigma(s, Bpu):
return s - math.sin(s) - math.pi * Bpu
def jac_sigma(s):
return 1 - math.cos(s)
if __name__ == '__main__':
Bpu = 0.5
sig_r = fsolve(sigma, x0=[math.pi], args=(Bpu), fprime=jac_sigma)
Run Code Online (Sandbox Code Playgroud)
运行上面的脚本会抛出以下错误,
Traceback (most recent call last):
File "C:\Users\RP12808\Desktop\_test_fsolve.py", line 12, in <module>
sig_r = fsolve(sigma, x0=[math.pi], args=(Bpu), fprime=jac_sigma)
File "C:\Users\RP12808\AppData\Local\Programs\Python\Python36\lib\site-packages\scipy\optimize\minpack.py", line 146, in fsolve
res = _root_hybr(func, x0, args, jac=fprime, **options)
File "C:\Users\RP12808\AppData\Local\Programs\Python\Python36\lib\site-packages\scipy\optimize\minpack.py", line 226, in _root_hybr
_check_func('fsolve', 'fprime', Dfun, x0, args, n, (n, …Run Code Online (Sandbox Code Playgroud) 我正在尝试运行这个程序。直到今天为止都运行良好。我的代码没有任何改变。
import lxml.etree
import urlparse
import re
def parse_url(url):
return lxml.etree.parse(url, lxml.etree.HTMLParser())
urlivv = "http://finance.yahoo.com/q?s=IVV"
docivv = parse_url(urlivv)
Run Code Online (Sandbox Code Playgroud)
这是我的错误消息:
IOError: Error reading file 'http://finance.yahoo.com/q?s=IVV': failed to load external entity "http://finance.yahoo.com/q?s=IVV"
网站上有一些关于添加StringIO参数的文档(见下文)。但我觉得很奇怪,我以前从未这样做过。
tree = etree.parse(StringIO(myString))
Run Code Online (Sandbox Code Playgroud)
编辑:更完整的堆栈跟踪。
>>> import lxml.etree
>>> tree = lxml.etree.parse('http://finance.yahoo.com/q?s=IVV', parser=lxml.etree.HTMLParser())
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "src\lxml\lxml.etree.pyx", line 3427, in lxml.etree.parse (src\lxml\lxml.etree.c:81100)
File "src\lxml\parser.pxi", line 1811, in lxml.etree._parseDocument (src\lxml\lxml.etree.c:117831)
File "src\lxml\parser.pxi", line 1837, in lxml.etree._parseDocumentFromURL (src\lxml\lxml.etree.c:118178)
File "src\lxml\parser.pxi", …Run Code Online (Sandbox Code Playgroud) python ×10
factorial ×1
game-engine ×1
java ×1
javascript ×1
keras ×1
legend ×1
lxml ×1
matplotlib ×1
memoization ×1
numpy ×1
pandas ×1
parsing ×1
r ×1
regex ×1
scipy ×1
selenium ×1
statsmodels ×1
subplot ×1
sympy ×1
xml.etree ×1
xpath ×1