小编lar*_*ars的帖子

使用 Spark 和 IntelliJ 时出现 NoSuchMethodError

我是 Scala 和 Spark 的新手。我对使用 IntelliJ 进行工作如此困难感到沮丧。目前,我无法运行下面的代码。我确信这很简单,但我无法让它发挥作用。

我正在尝试运行:

import org.apache.spark.{SparkConf, SparkContext}

object TestScala {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
    conf.setAppName("Datasets Test")
    conf.setMaster("local[2]")
    val sc = new SparkContext(conf)
    println(sc)
  }
}
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:

Exception in thread "main" java.lang.NoSuchMethodError: scala.Predef$.refArrayOps([Ljava/lang/Object;)Lscala/collection/mutable/ArrayOps;
at org.apache.spark.util.Utils$.getCallSite(Utils.scala:1413)
at org.apache.spark.SparkContext.<init>(SparkContext.scala:77)
at TestScala$.main(TestScala.scala:13)
at TestScala.main(TestScala.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Run Code Online (Sandbox Code Playgroud)

我的 build.sbt 文件:

name := "sparkBook"

version := "1.0"

scalaVersion := "2.12.1"
Run Code Online (Sandbox Code Playgroud)

jvm scala intellij-idea apache-spark

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

无法在Matplotlib中绘制条形图

使用此代码,

x = [420.0, 4353.0, 4373.0]; y = [269.0, 252.0, 283.0]
plt.bar(x,y)
plt.show()
Run Code Online (Sandbox Code Playgroud)

我得到:

空条形图

酒吧在哪里?如何让他们出现?

python matplotlib bar-chart

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

Lua中doFile和require之间有什么区别

在Lua中,doFile和require之间有什么区别,特别是在Torch中?你什么时候打电话给另一个而不打另一个?什么时候会工作但另一个不会?(我正在使用Lua 5.1,火炬7).

lua torch

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

试图找到/理解Harris Corners的正确实现

我正在尝试了解如何计算Harris Corner M,如https://courses.cs.washington.edu/courses/cse455/07wi/homework/hw3/中所定义

看来你需要总结一堆补丁.

但是,我看到很多实现都是这样的:

  R = (Ix2.*Iy2 - Ixy.^2) - k*(Ix2 + Iy2).^2; 
Run Code Online (Sandbox Code Playgroud)

来自:http://web.engr.illinois.edu/~slazebni/spring14/harris.m

没有总结,你永远不会看补丁.

这些看起来并不等同于我.例如,像素5,5的"R"值仅为该像素的Ix2,Iy2和Ixy值的平方.然而,数学似乎建议你总结一个补丁,比如像素5,5.哪种实施是正确的?都?它们是等价的吗?

注意:Ix2 =图像I在x方向上的平方梯度Iy2是相同的,除了y方向Ixy = Ix.*Iy

此外,.*或.^是指示逐点乘法或取幂的matlab表示法.

matlab image-processing computer-vision

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

什么是Python string.maketrans("","")

 string.maketrans("","")
Run Code Online (Sandbox Code Playgroud)

 \x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13 
 \x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !"#$%&\'()*+,-./0123456789:;<=>?
 @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~
 \x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90
\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2
\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4
\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9
\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde
\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed
\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff
Run Code Online (Sandbox Code Playgroud)

这是什么意思?

它如何通过以下调用帮助删除字符串中的标点符号:

 import string
 myStr.translate(string.maketrans("",""), string.punctuation)
Run Code Online (Sandbox Code Playgroud)

python string punctuation python-2.7

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

这个函数如何:input.nn.MSECriterion_updateOutput(self,input,target)工作(在Lua/Torch中)?

我有这个功能:

    function MSECriterion:updateOutput(input, target)
        return input.nn.MSECriterion_updateOutput(self, input, target)
    end
Run Code Online (Sandbox Code Playgroud)

现在,

   input.nn.MSECriterion_updateOutput(self, input, target)
Run Code Online (Sandbox Code Playgroud)

返回一个数字.我不知道它是怎么做到的.我已经在调试器中一步步走了,似乎这只是计算一个没有中间步骤的数字.

 input is a Tensor of size 1 (say, -.234). And the 

 nn.MSECriterion_updateOutput(self, input, target) looks like it is just the function MSECriterion:updateOutput(input, target).
Run Code Online (Sandbox Code Playgroud)

我对如何计算数字感到困惑.

我很困惑为什么甚至允许这样做.参数输入是一个张量,它甚至没有任何名为nn.MSE input.nn.MSECriterion_updateOutput的方法.

lua function lua-table torch

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

确定您是否可以使用每种面额仅使用一次且最多使用 k 个硬币以 N 面额进行找零

这是硬币兑换问题的一个版本。因此,这是一个动态规划问题。

我知道如何确定您是否可以找零,如果您最多可以使用每种面额的一枚硬币,或者您最多可以使用 k 枚硬币,但不能同时使用两者。

algorithm knapsack-problem dynamic-programming coin-change

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

试图理解计算 Torch 中 LogSoftMax 输入的梯度的代码

代码来自:https : //github.com/torch/nn/blob/master/lib/THNN/generic/LogSoftMax.c

我没有看到这段代码如何计算模块 LogSoftMax 输入的梯度。我感到困惑的是两个 for 循环在做什么。

for (t = 0; t < nframe; t++)
{
sum = 0;
gradInput_data = gradInput_data0 + dim*t;
output_data = output_data0 + dim*t;
gradOutput_data = gradOutput_data0 + dim*t;

for (d = 0; d < dim; d++)
  sum += gradOutput_data[d];

for (d = 0; d < dim; d++)
  gradInput_data[d] = gradOutput_data[d] - exp(output_data[d])*sum;
 }
}
Run Code Online (Sandbox Code Playgroud)

mathematical-optimization gradient-descent torch softmax

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

了解 Spark SQL 的一些基础知识

我正在关注http://spark.apache.org/docs/latest/sql-programming-guide.html

输入后:

val df = spark.read.json("examples/src/main/resources/people.json")

// Displays the content of the DataFrame to stdout
df.show()
// +----+-------+
// | age|   name|
// +----+-------+
// |null|Michael|
// |  30|   Andy|
// |  19| Justin|
// +----+-------+
Run Code Online (Sandbox Code Playgroud)

我有一些问题没有看到答案。

首先,什么是 $ 符号?如在

 df.select($"name", $"age" + 1).show()
Run Code Online (Sandbox Code Playgroud)

其次,我可以只从第二行获取数据吗(而且我不知道第二行的数据是什么)。

第三,如何使用 Spark sql 读取彩色图像?

第四,我仍然不确定spark中的数据集和数据帧之间有什么区别。变量 df 是一个数据帧,那么我可以将“Michael”更改为整数 5 吗?我可以在数据集中做到这一点吗?

scala apache-spark apache-spark-sql apache-spark-dataset

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