const有问题.说我有:
class A{
friend std::ostream& operator<<(std::ostream& os,const A& myObj);
private:
std::map<int,int> someMap;
int someInteger;
};
std::ostream& operator<<(std::ostream& os,const A& myObj){
os<<myObj.someInteger<<std::endl;
os<<myObj.someMap[0]<<std::endl;
}
Run Code Online (Sandbox Code Playgroud)
由于与地图的const冲突,这种代码在编译时会产生错误(如果我注释打印地图值的行一切都很好),如果我摆脱了函数原型中的'const',一切都很好.我真的没有看到问题在哪里..
有什么帮助吗?
Pandas 不会将我的数组转换为时间戳数组:
a = np.array([1457392827660434006, 1457392828660434012, 1457392829660434023,1457474706167386148])
pd.Timestamp(a)
Run Code Online (Sandbox Code Playgroud)
给出一个错误:
TypeError Traceback (most recent call last)
<ipython-input-42-cdf0e494942d> in <module>()
1 a = np.array([1457392827660434006, 1457392828660434012, 1457392829660434023,1457474706167386148])
----> 2 pd.Timestamp(a)
pandas/tslib.pyx in pandas.tslib.Timestamp.__new__ (pandas/tslib.c:8967)()
pandas/tslib.pyx in pandas.tslib.convert_to_tsobject (pandas/tslib.c:23508)()
TypeError: Cannot convert input to Timestamp
Run Code Online (Sandbox Code Playgroud)
而数组元素上的循环工作得很好:
for i in range(4):
t = pd.Timestamp(a[i])
print t
Run Code Online (Sandbox Code Playgroud)
给出:
2016-03-07 23:20:27.660434006
2016-03-07 23:20:28.660434012
2016-03-07 23:20:29.660434023
2016-03-08 22:05:06.167386148
Run Code Online (Sandbox Code Playgroud)
正如预期的那样。
此外,当该数组是 csv 文件中的第一列时,即使我正确指定了 parse_date,它也不会自动解析为时间戳。
有什么帮助吗?
请考虑这个简单的例子
nb_samples = 100000
X = np.random.randn(nb_samples)
Y = X[1:]
X = X[:-1]
X = X.reshape((len(Y), 1, 1))
Y = Y.reshape((len(Y), 1))
Run Code Online (Sandbox Code Playgroud)
所以我们基本上
Y[i] = X[i-1]
Run Code Online (Sandbox Code Playgroud)
并且该模型只是一个滞后算子。
我可以使用无状态 LSTM 来学习这个模型,但我想在这里了解并在 Keras 中应用有状态 LSTM。
所以我尝试用有状态的 LSTM 来学习这个模型,方法是(x, y)一个接一个地给出值对(batch_size = 1)
model = Sequential()
model.add(LSTM(batch_input_shape=(1, 1, 1),
output_dim =10,
activation='tanh', stateful=True
)
)
model.add(Dense(output_dim=1, activation='linear'))
model.compile(loss='mse', optimizer='adam')
for epoch in range(50):
model.fit(X_train,
Y_train,
nb_epoch = 1,
verbose = 2,
batch_size = 1,
shuffle = False)
model.reset_states()
Run Code Online (Sandbox Code Playgroud)
但是模型没有学到任何东西。
根据 Marcin …
我有这种形式的二维numpy数组:
[[ 0. 1. 2. 3. 4.]
[ 5. 6. 7. 8. 9.]
[ 10. 11. 12. 13. 14.]
[ 15. 16. 17. 18. 19.]
[ 20. 21. 22. 23. 24.]
[ 25. 26. 27. 28. 29.]
[ 30. 31. 32. 33. 34.]
[ 35. 36. 37. 38. 39.]
[ 40. 41. 42. 43. 44.]
[ 45. 46. 47. 48. 49.]]
Run Code Online (Sandbox Code Playgroud)
我想构造一个数组视图,将它的元素分组在一个移动窗口中(在我的示例中大小为4)。我的结果应该是形状(6, 4, 5),可以将其构造如下:
res = []
mem = 4
for i in range(mem, X.shape[0]+1):
res.append(X[i-mem:i, : ]) …Run Code Online (Sandbox Code Playgroud) 我正在尝试在龙卷风中编写一个简单的推送引擎。基本上,我有一个程序在我的服务器上运行,不断生成一个输出,我通过 Python 处理该输出以更新字典,并且我希望将该字典发布到 Web 客户端,例如每分钟发布一次。
如果您的答案包含文档链接或重新表述我自己的问题,我将不胜感激。我正在阅读大量痛苦的龙卷风文档,因此任何帮助将不胜感激。
这是代码的框架,其中有注释解释我想要做什么:
import subprocess
import sys
import pprint
import tornado.ioloop
import tornado.web
# this is to run my bash process and continuously yiled its output
def runProcess(cmd):
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
while True:
retcode = p.poll()
line = p.stdout.readline()
yield line
if retcode is not None:
break
class MainHandler(tornado.web.RequestHandler):
def get(self):
#What can I do here if I want to send the update data every minute?
self.write(data)
def get_data(self):
data = dict()
cmd = 'myProg …Run Code Online (Sandbox Code Playgroud) 我正在研究SICP,编写了两个过程来计算1 / n ^ 2的总和,第一个过程生成一个递归过程,第二个过程生成一个迭代过程:
(define (sum-rec a b)
(if (> a b)
0
(exact->inexact (+ (/ 1 (* a a)) (sum-rec (1+ a) b)))))
(define (sum-it a b)
(define (sum_iter a tot)
(if (> a b)
tot
(sum_iter (1+ a) (+ (/ 1 (* a a)) tot))))
(exact->inexact (sum_iter a 0)))
Run Code Online (Sandbox Code Playgroud)
我测试了两个过程在使用较小的值调用时给出的结果完全相同b,并且结果接近$ pi ^ 2/6 $ b,并且随着预期的增大而变大。
但是令人惊讶的是,呼叫(sum-rec 1 250000)几乎是瞬时的,而呼叫却(sum-it 1 250000)要花很长时间。
有什么解释吗?
我有一个大熊猫数据框,其中包含列时间戳,名称和值
index timestamp name value
0 1999-12-31 23:59:59.000107 A 16
1 1999-12-31 23:59:59.000385 B 12
2 1999-12-31 23:59:59.000404 C 25
3 1999-12-31 23:59:59.000704 B 15
4 1999-12-31 23:59:59.001281 A 300
5 1999-12-31 23:59:59.002211 C 20
6 1999-12-31 23:59:59.002367 C 3
Run Code Online (Sandbox Code Playgroud)
我想按时间段(例如20ms或20分钟)和名称进行分组,然后计算每组的平均值。
最有效的方法是什么?