小编col*_*ang的帖子

geom_line(stat ="hline")和geom_hline有什么区别?

我想绘制一条水平线yintercept = mean(y)的数据(x,y)

geom_line(stat="hline", linetype="dotted", yintercept="mean") 工作正常,但是

geom_hline(linetype="dotted", yintercept="mean") 对我不起作用?

我想知道这两个功能有什么区别?我以为geom_hline= geom_line+ stat_hline.不是吗?

更新

这里回答`geom_a(stat ="b",...)`和`stat_b(geom ="a",...)`之间有什么区别吗?

geom_hline 太奇怪了!

r ggplot2

1
推荐指数
1
解决办法
2463
查看次数

cython不支持带键排序?

def test():
    return sorted([(a,b) for a in xrange(10) for b in xrange(10)],
       key=lambda (x,y): x + y)
Run Code Online (Sandbox Code Playgroud)

上面是有效的python代码,但会触发cython错误。错误消息是Expected ')', found ','

怎么了

Python 2.7,Cython 0.19.2

python cython

1
推荐指数
1
解决办法
302
查看次数

`use`关键字不适用于咖喱形式?

let make f =
  printfn "1"
  use file = File.CreateText("abc.txt")
  let v = f file
  printfn "2"
  v

let f (x: StreamWriter) (y:int) = 
  printfn "3"
  x.WriteLine("{0}", y)

let a = make f

> 1
> 2
> val a : (int -> unit)

a 8

System.ObjectDisposedException: The object was used after being disposed.
Run Code Online (Sandbox Code Playgroud)

编译时没有给我任何错误或警告,但在运行时它会触发这样的错误.

我是否必须使用完整版本let make f y = ...以避免咖喱形式?

f#

1
推荐指数
1
解决办法
71
查看次数

为什么`&mut&foo`有效,但`&mut a_ref_to_foo`无效?

在以下示例中,t1编译但t2不编译.

有什么特别的&mut &stream吗?我不认为Deref踢.

use std::net::TcpStream;

fn t1() {
    let stream = TcpStream::connect("127.0.0.1").unwrap();
    let a = &mut &stream;
}

fn t2(stream: &TcpStream) {
    let a = &mut stream;
}
Run Code Online (Sandbox Code Playgroud)

操场

9  | fn t2(stream: &TcpStream) {
   |       ------ use `mut stream` here to make mutable
10 |     let a = &mut stream;
   |                  ^^^^^^ cannot borrow mutably
Run Code Online (Sandbox Code Playgroud)

rust

1
推荐指数
1
解决办法
71
查看次数

这两个linq查询之间是否有任何性能差异,它们是相同还是本质上不同?

另外,where子句的顺序是否重要?

  from x in A.where(x=>CriteriaA(x))
  from y in B where(y=>CriteriaB(y))
  where CriteriaC(x,y)


  from x in A
  from y in B
  where(x=>CriteriaA(x))
  where(y=>CriteriaB(y))
  where CriteriaC(x,y)

  from x in A
  from y in B
  where(y=>CriteriaB(y))
  where(x=>CriteriaA(x))
  where CriteriaC(x,y)
Run Code Online (Sandbox Code Playgroud)

更新:所有都是IEnumerable <>和Linq to Objects

使用Jon Skeet的场景:A有100个条目,其中25个匹配CriteriaA B有100个条目,其中50个匹配CriteriaB

第一种方法,将有100个呼叫CriteriaA,2500个呼叫CriteriaB和1250个呼叫CriteriaC.

第二种方法,将有10000个呼叫CriteriaA,2500个呼叫CriteriaB和1250个呼叫CriteriaC.

第三种方法,将有10000个呼叫CriteriaB,5000个呼叫CriteriaA和1250呼叫CriteriaC.

那是对的吗?

c# linq

0
推荐指数
1
解决办法
87
查看次数

如何使用.net数组?

我读到了处理数组时我们应该使用myArray.[i],但是,根据我的经验myArray[i]编译也是如此.

但是,当我想写入.Net中的数组(因此它是可变的)时,这会产生错误 let myArray.[i] = 3但是let myArray[i] =3有效.

处理此类事情的最佳做法是什么?

另外,我应该使用Array.get还是使用.[]

如何将值设置为锯齿状数组,例如 let myArray.[i].[j] = 5

.net arrays f#

0
推荐指数
1
解决办法
137
查看次数

在这种情况下如何处理序列构造,因为我们没有断点也没有强大的Seq.choose版本?

我希望我能做到:

 let myFun param1 param2 = 
      .....
      if condition 1
          ....
          if condition 2
               yield ....

 let sequence = seq { for x in xs do
                            myFun 1 x
                            myFun 2 x
                    }
Run Code Online (Sandbox Code Playgroud)

但现在我只能这样做

 let myFun param = 
      .....
      .....
      if condition 1
          ....
          if condition 2
               Some....
          else None    // has to complete else
      else None

 let sequence = seq { for x in xs do
                        match myFun 1 x with
                        | Some x -> yield x
                        | None …
Run Code Online (Sandbox Code Playgroud)

f#

0
推荐指数
1
解决办法
127
查看次数

R中是否有一个函数或包可以从分位数和概率中获得泊松分布的lambda?

例如,F(X = 2 | lambda = 2.3) = 0.596我知道2和0.596,我想得到lambda.

我知道我可以通过数值逼近算法来做到这一点.

然而,在我手动创建一个函数之前,是否有一个我可以简单使用的现有函数?

更新

遗憾的是我必须使用数值方法.我原以为有一种流行的着名分析方法/封闭形式.

r

0
推荐指数
1
解决办法
2066
查看次数

如何在宏中调用self方法?

macro_rules! call_on_self {
    ($F:ident) => {
        self.$F()
    }
}

struct F;
impl F {
    fn dummy(&self) {}
    fn test(&self) {
        call_on_self!(dummy);
    }
}
Run Code Online (Sandbox Code Playgroud)

以上不起作用:

error[E0424]: expected value, found module `self`
  --> src/lib.rs:3:9
   |
3  |         self.$F()
   |         ^^^^ `self` value is a keyword only available in methods with `self` parameter
...
11 |         call_on_self!(dummy);
   |         --------------------- in this macro invocation
Run Code Online (Sandbox Code Playgroud)

我希望生成宏

macro_rules! call_on_self {
    ($F:ident) => {
        self.$F()
    }
}

struct F;
impl F {
    fn dummy(&self) {}
    fn test(&self) …
Run Code Online (Sandbox Code Playgroud)

rust rust-macros

0
推荐指数
1
解决办法
1490
查看次数

如果n = myArray.Length或= myList.Count,这是一个很好的做法吗?

如果我们知道的话 int n = myArray.Length = myList.Count

那么,当我们需要使用这个值来表示数组/列表长度时,哪一个最好用?例如,我们使用var x=n*2 or var x=myArray.Length*2 or var x=myList.Count*2

相同的问题是,直接使用n而不是引用对象的成员属性会更有效吗?

c#

-1
推荐指数
1
解决办法
114
查看次数

标签 统计

f# ×3

c# ×2

r ×2

rust ×2

.net ×1

arrays ×1

cython ×1

ggplot2 ×1

linq ×1

python ×1

rust-macros ×1