我在Spark 1.3上.
我想将一个函数应用于数据帧的每一行.此函数散列行的每一列并返回散列列表.
dataframe.map(row => row.toSeq.map(col => col.hashCode))
Run Code Online (Sandbox Code Playgroud)
运行此代码时出现NullPointerException.我认为这与SPARK-5063有关.
如果不使用嵌套映射,我无法想到实现相同结果的方法.
我正在尝试编写一个脚本,它将从lazyfoo.net的教程中下载所有源代码.该文件的示例下载链接是
http://lazyfoo.net/downloads/index.php?file=SDLTut_lesson16
我用这个命令:
curl http://lazyfoo.net/downloads/index.php?file=SDLTut_lesson13 --O lesson13.zip
这让我得到了这个回复而没有文件:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
Run Code Online (Sandbox Code Playgroud)
我错过了一些明显的东西吗
我有一系列双打向量: val vectors = Seq[Vector[Double]]
我想对序列中的所有向量求和,即 val total = vectors.sum
例如,如果我有一个包含两个向量[1,2]和的序列[3,4],那么结果应该是[4,6]
但是,该类型的sum方法Vector需要一个隐式的Numeric.
我现在拥有的是:
val total = vectors.reduce( (one,two) => one.zip(two).map(tuple => tuple._1 + tuple._2) )
Run Code Online (Sandbox Code Playgroud)
我是 Scala 的新手,但我觉得这很令人困惑,我认为它可能效率低下。
有一个更好的方法吗?
我有一个点列表.我将其表示为ArrayLists的ArrayList.我正在尝试使用泛型,以便列表可以存储整数,浮点数等,并对它们进行相同处理.所以我有:
ArrayList<ArrayList<? extends Number>>.
Run Code Online (Sandbox Code Playgroud)
我需要根据每个内部列表中的一个元素来比较这些列表.
所以为了做到这一点,我写了一个我在Collections.sort中使用的自定义Comparator
比较器看起来像:
int compare(ArrayList<? extends Number> a, ArrayList<? extends Number> b )
{
return a.get(index).compareTo(b.get(index))
}
Run Code Online (Sandbox Code Playgroud)
当然这不编译.编译器抱怨通配符类没有compareTo方法.
我正在努力做甚么可能吗?
我正在努力从纸上实现算法.本文描述了使用网格,其中每个网格方块都包含一个整数的链接列表,这些整数表示该网格方块中的对象.
我决定使用它LinkedList<Integer>[][],这当然给了我一个generic array creation错误.
我想不出更好的方式来表示链表的网格.我也明白使用LinkedList[][]会编译但是不好的做法,因为它是无类型的.但是,我宁愿不使用,ArrayList<ArrayList<LinkedList<Integer>>>因为这是不可读的,至少对我而言.
有没有办法在LinkedList这里使用无类型?或者其他一些解决方案?
我知道当视图的代码路径没有返回时HttpResponse,这是显而易见的.我是django的新手,所以这可能是完全错误的.
这是FormView代码.我需要覆盖render_to_response吗?
class AddAdvertView(FormView):
form_class = NewAdForm
def get(self, *args, **kwargs):
self.campaign = get_object_or_404(Campaign, id__exact = self.kwargs['campaign_id'])
def post(self, request, *args, **kwargs):
pass
def get_form(self, form_class):
return form_class(initial = {}, campaign = self.campaign)
def get_success_url(self):
return self.request.META.get('HTTP_REFERER', None)
def form_valid(self, form):
return HttpResponse('form valid')
def form_invalid(self, form):
return HttpResponse('form invalid')
Run Code Online (Sandbox Code Playgroud) generics ×2
java ×2
apache-spark ×1
arraylist ×1
arrays ×1
collections ×1
curl ×1
django ×1
python ×1
scala ×1