里奥·梅西

Scala学习-集合相关操作

若如初见. 提交于 2020-02-27 23:11:21
接下来记录下scala中集合相关的知识,scala中集合分为可变集合和不可变集合,有Array、List、Set、Map和Tuple。 不可变 可变 数组Array Array ArrayBuffer 列表List List ListBuffer 散列Set immutable.Set mutable.Set 映射Map immutable.Map mutable.Map 元祖 Tuple 为了理解的方便,使用交互式方式REPL来完成。 数组 (1)定义一个定长数组。 scala> val a1=Array(4,1,2,5) a1: Array[Int] = Array(4, 1, 2, 5) scala> val a2=new Array[Int](4) a2: Array[Int] = Array(0, 0, 0, 0) (2)定义一个变长数组。 scala> val a3=scala.collection.mutable.ArrayBuffer(1,2,3,4) a3: scala.collection.mutable.ArrayBuffer[Int] = ArrayBuffer(1, 2, 3, 4) //1 添加一个元素 scala> a3+=5 res1: a3.type = ArrayBuffer(1, 2, 3, 4, 5) //2 添加一个元素 scala> a3

MapReduce实现好友推荐

对着背影说爱祢 提交于 2019-12-06 23:27:39
MapReduce可以实现一个简单的好友推荐,本文参考了文末博主的思路,个人感觉不错,自己修改部分代码也简单实现了,记录下。 数据准备 如下数据就是好友关系,同一行的两个人就是好友,需要在这数据里寻找两个人是否是潜在好友,即两人不是直接好友,但是却有共同的好友,需要将这样关系的两个人作为结果推荐出去。 clyang messi clyang herry clyang ronald messi clyang messi kaka messi ronald herry clyang herry kaka ronald herry ronald clyang ronald messi 思路分析 (1)首先按照第一个name来统计他的好友列表,即需要输出成clyang messi herry ronald这样一行行的数据,这样map的输出key就是第一个名字如clyang,value就是好友列表如messi herry ronald,这里使用一个MR来完成中间值的输出。 (2)根据上面MR的统计结果,在Map任务中,需将两人的名字和并到一起作为key,如果是直接好友,输出value记录为0,如果不是直接好友,但是有共同的好友,则value记录为1输出给reducer。用数字0和1来区分是否是直接好友,如clyang和messi是直接好友,则输出(clyang:messi, 0)

Why is matplotlib.PatchCollection messing with color of the patches?

匿名 (未验证) 提交于 2019-12-03 02:30:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I make a number of patches like so - node . shape = RegularPolygon (( node . posX , node . posY ), 6 , radius = node . radius , edgecolor = 'none' , facecolor = node . fillColor , zorder = node . zorder ) node . brushShape = RegularPolygon (( node . posX , node . posY ), 6 , node . radius * 0.8 , linewidth = 3 , edgecolor = ( 1 , 1 , 1 ), facecolor = 'none' , zorder = node . zorder ) And originally I was just putting them straight onto my axis like this - self . plotAxes . add_artist ( node . shape ) self . plotAxes . add_artist (

Why word 'translate' is messing irb?

匿名 (未验证) 提交于 2019-12-03 02:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I don't understand why my method translate undefines start_with? method and is messing something in irb, so I can exit irb only by pressing Ctrl + d , not exit or quit : >> "hello".respond_to?(:start_with?) => true >> def translate(string) >> if string.start_with?("a", "e", "i", "o", "u") >> string += "ay" >> end >> end NoMethodError: undefined method `start_with?' for # from (irb):3:in `translate' from /usr/local/rvm/rubies/ruby-2.3.0/bin/irb:11:in ` ' >> "hello".respond_to?(:start_with?) NoMethodError: undefined method `start_with?' for