scipy.spatial.distance.pdist返回压缩距离矩阵.从文档:
返回压缩距离矩阵Y.对于每个和(where),度量dist(u = X [i],v = X [j])被计算并存储在条目ij中.
我以为ij是的意思i*j.但我想我可能错了.考虑
X = array([[1,2], [1,2], [3,4]])
dist_matrix = pdist(X)
Run Code Online (Sandbox Code Playgroud)
然后文档说dist(X[0], X[2])应该是dist_matrix[0*2].但是,dist_matrix[0*2]它应该是0 - 而不是2.8.
我应该使用什么公式来获取两个向量的相似性,给定i和j?
我一直在研究inotify调用,但在读取界面方面我仍然有点不稳定.这些是关于如何使用read(2)正确连接inotify的最相关的资源:
它们都以相同的方式实现它们,它们首先定义以下大小:
#define EVENT_SIZE ( sizeof (struct inotify_event) )
#define BUF_LEN ( 1024 * ( EVENT_SIZE + 16 )
Run Code Online (Sandbox Code Playgroud)
然后他们以这种方式使用它们:
length = read( fd, buffer, BUF_LEN );
if ( length < 0 ) {
perror( "read" );
}
while ( i < length ) {
struct inotify_event *event = ( struct inotify_event * ) &buffer[ i ];
/* some processing */
i += EVENT_SIZE + event->len;
}
Run Code Online (Sandbox Code Playgroud)
现在,我们知道名称是其中的一部分,struct inotify_event并且它具有可变长度.那么,缓冲区中的最后一个inotify_event是否会被截断?
假设有1023个inotify_events,路径为16个字节,另一个路径为32个字节.那会发生什么?后来会被截断吗?或者内核是否会看到它不适合缓冲区并完全放弃?
我有两张桌子:律师和电话.电话分为区号和号码.律师有很多电话.我想制作一个查询,搜索手机列表中有手机匹配手机的律师.
如果我只有一部手机,我可以像这样搜索:
Lawyer.join(:phones).where(:area_code => area_code, :number => number)
Run Code Online (Sandbox Code Playgroud)
问题是我有一个包含多个区号的列表.所以我真的想做这样的事情:
lawyers = []
phones.each { |phone| lawyers += Lawyer.join(:phones).where(:area_code => phone[:area_code], :number => phone[:number]) }
Run Code Online (Sandbox Code Playgroud)
但是,我不想提出很多疑问.不能在单个查询语句中完成吗?
编辑:这就是我单独使用SQL做类似的事情(假设数字列表是[{:area_code =>'555',:number =>'1234564'},{:area_code =>'533',:数> '12345678'}])
select * from phones where (area_code, number) in (('555', '1234564'), ('533', '12345678'))
Run Code Online (Sandbox Code Playgroud)
如果有人可以将其翻译成ActiveRecord,那就太好了.
我对此处描述的代码稍作更改,以便跟踪出站链接点击次数.这是我的代码:
function recordOutboundLink(link, label) {
try {
var myTracker=_gat._getTrackerByName();
_gaq.push(['myTracker._trackEvent', 'Outbound Links', label, link.href ]);
setTimeout('document.location = "' + link.href + '"', 100)
}catch(err){}
}
Run Code Online (Sandbox Code Playgroud)
然后我将它添加到我的href标签中,如下所示:
<a href="http://example.com/user/5" onclick="recordOutboundLink(this, 'example.com');return false"></a>
Run Code Online (Sandbox Code Playgroud)
不过,我认为它不起作用.检查它是否有效真的很难.我该如何检查它是否正常工作?
编辑:使用谷歌分析调试程序的chrome我能够看到发生了什么.它显示:
Account ID : UA-XXXXX-X
Run Code Online (Sandbox Code Playgroud)
这很奇怪,因为正常的页面跟踪正在按预期工作.这就是我设置谷歌分析代码的方式:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'my-id']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
Run Code Online (Sandbox Code Playgroud) 我真的想在活动记录的帮助下进行以下查询
(select *
from people p join cities c join services s
where p.city_id = c.id and p.id = s.person_id and s.type = 1)
intersect
(select *
from people p join cities c join services s
where p.city_id = c.id and p.id = s.person_id and s.type = 2)
Run Code Online (Sandbox Code Playgroud)
问题是,首先,mysql不支持交叉.但是,这可以解决.问题是我可以获得活动记录来输出甚至接近它的任何东西.
在活动记录中,我能做的最好的事情就是发出多个查询然后reduce :& 用来加入它们,但后来我得到一个数组,而不是一个关系.这对我来说是一个问题,因为我想调用限制等等.另外,我认为交叉点要由数据库完成,而不是ruby代码.
我经常想使用STL函数和容器,我发现自己必须手动添加:
#include <vector>
using std::vector;
Run Code Online (Sandbox Code Playgroud)
到文件的开头.是否有人知道vim插件或命令行程序会自动执行此类操作?
为什么在 input#q 上输入任何内容都会挂起整个页面?
<html>
<head></head>
<body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="q">
<input>
<script type="text/javascript">
$("#q").keydown(function() {
while(true) {
}
});
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我期望的行为是处理该特定 keydown 事件的线程会阻塞,但页面将保持响应。我进行了测试,因为我很想知道该代码是否会阻止用户在 input#q 上输入。然而,它远不止于此:整个页面块(我在 Chrome、Firefox 和 Safari 上尝试过)。
我继续尝试这个:
setTimeout(function() {
while(true){}
}, 5000);
Run Code Online (Sandbox Code Playgroud)
5 秒后页面挂起。没有更多的交互是可能的。那不应该在不同的线程上吗?javascript 和所有其他与页面的交互是否在同一线程上运行?
activerecord ×2
c ×1
c++ ×1
inotify ×1
javascript ×1
jquery ×1
linux-kernel ×1
mysql ×1
numpy ×1
python ×1
scipy ×1
vim ×1