我遇到Numpy矩阵问题
我想这样做; 我正在使用" googlefinance"库提供实时股票价格数据,从这里,我想制作一个我拉的数据矩阵。例如,
<?php
if(empty($_POST)){
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Testing</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$( "#myform2, #myform3" ).submit(function( event ) {
event.preventDefault();
console.log(this,$(this).find(":input,:button").serializeArray());
alert('submit')
this.submit();
});
});
</script>
</head>
<body>
<form name="myform" id="myform1" method="post">
<button value="button-value" name="button" type="submit">button</button>
<input type="test" value="123" name="data">
</form>
<form name="myform" id="myform2" method="post">
<button value="button-value" name="button" type="submit">button</button>
<input type="test" value="123" name="data">
</form>
<form name="myform" id="myform3" method="post">
<input value="button-value" name="button" type="submit">
<input type="test" value="123" name="data">
</form>
</body>
</html>
<?php
}
else {echo('<pre>'.print_r($_POST,1).'</pre>');}
?>
这将给我目前的股票实时价格&#39; a&#39;
我想制作一个像这样的矩阵;
from googlefinance import getQuotes
def live_price(symbol):
price = getQuotes(symbol)[0].values()[3]
return float(price)
live_price('a')
输出:
A=np.matrix([live_price('a'),live_price('b'),live_price('c')])
这就是问题所在。问题是当我在10秒后运行matrix([[37.69, 9.04, 34.23]])
时,它会给我一个包含更新价格数据的矩阵,因为每次Google财务刷新价格数据时A
都会刷新数据。
如果我每次只运行live_price('symbol')
价格变动,它会给我更改的新价格。但是当它处于numpy矩阵中时,价格没有更新,它总是给我与我制作numpy矩阵时的价格相同的价格。我该如何解决这个问题。我希望每次运行live_price('a')
时,numpy矩阵A
都会更新价格。
答案 0 :(得分:1)
你应该跑十秒钟:
A[0,0] = live_price('a')
更新矩阵的第一个元素。
对于您的心理健康,'明确胜于隐性'。