且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

朱莉娅:检查一个向量中的元素是否在另一向量内

更新时间:2023-11-29 20:18:04

有许多内置插件可以执行类似的操作. indexin为您提供在b中找到a元素的索引(如果不存在,则为0,这类似于R的match). setdiff为您提供a中的元素,而这些元素不在b中.您很可能可以使用它们来做您想做的-在julia中构造用于过滤的临时布尔数组并不像R中那样意识形态,因为它通常会创建额外的不必要分配.

There are a number of built-ins that do something similar. indexin gives you the indices in b where the elements of a are found (0 if it is not there - this is similar to R's match). setdiff gives you the elements in a that are not in b. It is likely you'll be able to do what you want with these - constructing temporary boolean arrays for filtering is not so ideomatic in julia as in R, as it generally creates an extra, unnecessary allocation.