这是对数刻度中的网络IP频率等级图.完成此部分后,我试图使用Python 2.7在log-log标度上绘制最佳拟合线.我必须使用matplotlib的"symlog"轴刻度,否则一些值不能正确显示,一些值会被隐藏.
我正在绘制的数据的X值是URL,Y值是URL的相应频率.
我的数据看起来像这样:
'http://www.bing.com/search?q=d2l&src=IE-TopResult&FORM=IETR02&conversationid= 123 0.00052210688591'
`http://library.uc.ca/ 118 4.57782298326e-05`
`http://www.bing.com/search?q=d2l+uofc&src=IE-TopResult&FORM=IETR02&conversationid= 114 4.30271029472e-06`
`http://www.nature.com/scitable/topicpage/genetics-and-statistical-analysis-34592 109 1.9483268261e-06`
Run Code Online (Sandbox Code Playgroud)
数据包含第一列中的URL,第二列中的相应频率(相同URL存在的次数),最后是第3列中传输的字节.首先,我只使用第1列和第2列进行此分析.共有2,465个x值或唯一网址.
以下是我的代码
import os
import matplotlib.pyplot as plt
import numpy as np
import math
from numpy import *
import scipy
from scipy.interpolate import *
from scipy.stats import linregress
from scipy.optimize import curve_fit
file = open(filename1, 'r')
lines = file.readlines()
result = {}
x=[]
y=[]
for line in lines:
course,count,size = line.lstrip().rstrip('\n').split('\t')
if course not in result:
result[course] = int(count)
else:
result[course] += …Run Code Online (Sandbox Code Playgroud) 所以结构是{{Dog,Cat,Human},{Human,Dog,Whale,rabbit,Cow},{Monkey,Human,Dog}}.
输出应该是:Dog,Human.
我必须在较大的List中找到List元素的交集.以前,我已经看到了找到相互交叉的代码ArrayLists,但不知道我怎么能在同一个ArrayList(两个以上)内完成.
对于单独ArrayLists的代码,如下所示.但是如何让它更适合多个ArrayLists内部ArrayList?我在接受采访时被问到这个问题.为单独的列表工作,但不能用它来粉笔ArrayList.
面试官明确规定只与字符串的工作,所以我修改了泛型类型令牌从{<T>}以{<String>}澄清之后.
public class Test {
public <String> List<String> intersection(List<String> list1, List<String> list2) {
List<String> list = new ArrayList<>();
for (String t: list1) {
if(list2.contains(t)) {
list.add(t);
}
}
return list;
}
public static void main(String[] args) throws Exception {
List<String> list1 = new ArrayList<String>(Arrays.asList("Dog", "Cat", "Human"));
List<String> list2 = new ArrayList<String>(Arrays.asList("Human", "Dog", "Whale", "rabbit", "Cow"));
System.out.println(new …Run Code Online (Sandbox Code Playgroud) 我试图将 Scala HashMap 的键与值列表进行比较,如果列表中不存在该键,我需要将 Map 的值更新为默认值 -1。
例如:考虑以下情况:
列表:
val pos = List("100","110")
Run Code Online (Sandbox Code Playgroud)
地图:
scala> idSizeMap
res2: scala.collection.immutable.Map[String,Long] = Map(100 -> 4240070722, 110 -> 611884363, 120 -> 1825405636, 130 -> 2194234, 72 -> 3685020648)
Run Code Online (Sandbox Code Playgroud)
使用filterKeys我可以做类似交集的操作
scala> val result = idSizeMap.filterKeys(pos.contains)
result: scala.collection.immutable.Map[String,Long] = Map(100 -> 4240070722, 110 -> 611884363)
Run Code Online (Sandbox Code Playgroud)
但我也希望旧地图中的键具有默认值 -1。预期输出:
Map(100 -> 4240070722, 110 -> 611884363, 120 -> -1, 130, -1, 72 -> -1)
Run Code Online (Sandbox Code Playgroud)
我还尝试了以下操作,它执行与 filterKeys 相同的操作:
var similarItems = Map[String, Long]()
similarItems: scala.collection.immutable.Map[String,Long] = Map()
scala> for (eachpos …Run Code Online (Sandbox Code Playgroud) arraylist ×1
data-science ×1
dictionary ×1
hadoop ×1
ip ×1
java ×1
matplotlib ×1
python ×1
scala ×1