小编m0n*_*awk的帖子

在C中循环大向量的整数溢出?

我们可以使用for循环迭代C中的向量,例如:

int len = length(x);
for (int i=0; i<len; i++) {
    double val = REAL(x)[i];
}
Run Code Online (Sandbox Code Playgroud)

这似乎工作正常,但我不明白为什么.根据维基百科,默认int类型的范围是-32767到+32767.那么为什么这仍然适用于比这更长的载体?

R是否会int以某种方式覆盖long int?这段代码支持的向量的最大长度是多少?

c

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

在 Haskell 中使用 Maybe [String]

我想使用Maybe [String] 返回一个字符串,但我无法使用Maybe 来实现。

我应该定义一个实例吗?

data Contacto = Casa Integer
              | Trab Integer
              | Tlm Integer
              | Email String
              deriving (Show)
type Nome = String
type Agenda = [(Nome, [Contacto])]

addEmail :: Nome -> String -> Agenda -> Agenda
addEmail n email agenda = (n, [Email email]):(agenda)


verEmails :: Nome -> Agenda -> [String]
verEmails n [] = []
verEmails n ((nome, ((Email e):ls)):xs) = if n == nome then (e:(verEmails n xs))
                                                       else (verEmails n xs)
Run Code Online (Sandbox Code Playgroud)

这是相同的函数 verEmails,我在其中使用了 Maybe: …

haskell

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

C#多次重复IEnumerable

如何重复整体 IEnumerable多次?

与Python类似:

> print ['x', 'y'] * 3
['x', 'y', 'x', 'y', 'x', 'y']
Run Code Online (Sandbox Code Playgroud)

c# ienumerable

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

Dumb rbind for data.frames of different length

我不需要任何的智能 rbind,如rbindlist,rbind.fill,bind_row等.

我需要一个哑巴rbind才能简单地绑定两个数据帧:

> a <- data.frame(a = 1:3)
> b <- data.frame(b = 1:2)

> some.magic.bind(a, b) # what function to use here?

   a  b
1  1 1
2  2 2
3  3 NA
Run Code Online (Sandbox Code Playgroud)

r dataframe cbind

2
推荐指数
2
解决办法
210
查看次数

ElasticsearchIllegalArgumentException没有名称的功能

我有一个Elasticsearch节点设置.当我通过curl命令查询索引时,我得到了预期的输出.

curl -XPOST 'http://localhost:9200/one/employee/_search?pretty=true' -d '{
"query": {
"term": {
"emp_id":"4318W01149"
}
}
}'
Run Code Online (Sandbox Code Playgroud)

但是当我通过浏览器运行类似的查询时,我得到错误

http://localhost:9200/one/employee/?q=emp_id:4318W01149

{"error":"ElasticsearchIllegalArgumentException[No feature for name [employee]]","status":400}
Run Code Online (Sandbox Code Playgroud)

我在ES版本1.5.2上

谢谢

elasticsearch

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

检查R中向量中的值

请参阅以下代码.id <- 1:10.如何避免警告?

allFiles <- list.files(directory)

fileRange <- c(1:length(allFiles))
if(!(as.numeric(id) %in% fileRange))
{
  print("Invalid file range")
  stop()
}
Run Code Online (Sandbox Code Playgroud)
Warning: the condition has length > 1 and only the first element will be used
Run Code Online (Sandbox Code Playgroud)

r

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

将树缩减为haskell中的列表

我正在尝试将树减少到列表,但我被困在这里..任何建议都赞赏..

data Tree a = Leaf a | Node (Tree a) a (Tree a) deriving (Eq, Show)
treeToList :: (Ord a) => Tree a -> [a]
treeToList (Node root left right) = treeToList left ++ [root] ++   treeToList right
Run Code Online (Sandbox Code Playgroud)

期待结果:

ghci> treeToList (Node (Leaf 1) 2 (Node (Leaf 3) 4 (Leaf 5)))

[1,2,3,4,5]
Run Code Online (Sandbox Code Playgroud)

haskell

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

有没有办法减少if语句?

该程序应打印出每个数字生成100个随机数的次数,范围为1到10(然后将其放入数组中).

我想不出任何其他方式,而不是每个数字都有一个if语句.有没有办法避免使用其他代码或其他东西的那么多if语句?

public static void countNumbers() {
    Random generator = new Random();

    int arr[] = new int[101];
    int add[] = new int[10];

    for (int i = 0; i < 100; i++) {
        int sum = 0;
        arr[i] = generator.nextInt(10)+1;

        if(arr[i] ==1){
            add[0]++;
        }
        if(arr[i] ==2){
            add[1]++;
        }
        if(arr[i] ==3){
            add[2]++;
        }
        if(arr[i] ==4){
            add[3]++;
        }
        if(arr[i] ==5){
            add[4]++;
        }
        if(arr[i] ==6){
            add[5]++;
        }
        if(arr[i] ==7){
            add[6]++;
        }
        if(arr[i] ==8){
            add[7]++;
        }
        if(arr[i] ==9){
            add[8]++;
        }
        if(arr[i] ==10){
            add[9]++;
        }
    } …
Run Code Online (Sandbox Code Playgroud)

java if-statement

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

Scala 不从资源文件夹中读取文件

为什么下面没有war-and-peace.txtresources文件夹中读取文件?

我的项目中的文件夹结构是使用 Intellij 创建的标准 Scala 结构。

出于某种原因,它仅在我将它放入src/main/scala(即我的 Scala 代码所在的位置)时才读取该文件,但是当我将它放入src/main/resources(在后一种情况下我得到java.lang.NullPointerException,顺便说一句,我也得到相同的异常时忽略该文件当我尝试阅读"/war-and-peace.txt"(带有前面的斜线)以防您想提出建议时)。

val file = new File(classLoader.getResource("war-and-peace.txt").getFile())

Source.fromFile(file).....
Run Code Online (Sandbox Code Playgroud)

我在用

java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)
Run Code Online (Sandbox Code Playgroud)

构建.sbt:

name := "my-project"

version := "1.0"

scalaVersion := "2.11.8"

resourceDirectory in Compile := baseDirectory.value / "resources"

libraryDependencies += "junit" % "junit" % "4.12"

libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.4"
Run Code Online (Sandbox Code Playgroud)

scala sbt intellij-15

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

如何在python中绘制semilog图?

如何在python中绘制semilog图?日志中的X轴和线性的y轴.目前我在plooting阶段vs omega,我需要y轴是线性的,而x轴是log.我可以在python中做到这一点吗?

python plot matplotlib

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