我有一个名为"a"的100000000x2数组,第一列中有索引,第二列中有相关值.我需要为每个索引获取第二列中数字的中值.这就是我用for语句做的事情:
import numpy as np
b = np.zeros(1000000)
a = np.array([[1, 2],
[1, 3],
[2, 3],
[2, 4],
[2, 6],
[1, 4],
...
...
[1000000,6]])
for i in xrange(1000000):
b[i]=np.median(a[np.where(a[:,0]==i),1])
Run Code Online (Sandbox Code Playgroud)
对于迭代来说显然它太慢了:任何建议?谢谢
我在我的网页上插入了一些js代码(由第三方服务提供),这打破了我的html验证.我该如何解决这个问题?CDATA没有做到这一点.这是我的示例代码段:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>test</title>
<script type="text/javascript">
/*<![CDATA[*/
document.write('<script src="//sharebutton.net/plugin/sharebutton.php?type=horizontal&u=' + encodeURIComponent(document.location.href) + '"></scr' + 'ipt>');
/*]]>*/
</script>
</head>
<body>
<p>test</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
而在这里,你可以找到验证的结果.