我的代码
with open('freq1.txt') as f:
next(f, None)
list1 = [line.rstrip() for line in f]
with open('freq2.txt') as f:
next(f, None)
list2 = [line.rstrip() for line in f]
print set(list1).intersection(list2)
Run Code Online (Sandbox Code Playgroud)
但是我得到了set([])例如我有两个列表
list1=[1,2,3,4]
list2=[3,2,7,5,9]
Run Code Online (Sandbox Code Playgroud)
我想列出list1和list2中的所有元素
newlist=[1,2,3,4,5,7,9]
Run Code Online (Sandbox Code Playgroud)
怎么写这个?
编辑我想使用列表推导的一种方式.
list1=[1.0,2.0,3.1,4.2]
list2=[3.0,2.0,7.2,5.1,9.2]
list3=[2.1,4.2,5.1,9.2]
su1 = list1 + [x for x in list2 if x not in list1]
su2= su1 + [x for x in list3 if x not in su1]
su2=sorted(su2)
print su2list1=[1.0,2.0,3.1,4.2]
list2=[3.0,2.0,7.2,5.1,9.2]
list3=[2.1,4.2,5.1,9.2]
su1 = list1 + [x for x in list2 …
Run Code Online (Sandbox Code Playgroud) 我试图将gpu标记到我的节点这不起作用
kubectl label node gke-kubia-default-pool-98519add-25c1/10.164.0.3 gpu=true
error: there is no need to specify a resource type as a separate argument when passing arguments in resource/name form (e.g. 'kubectl get resource/<resource_name>' instead of 'kubectl get resource resource/<resource_name>'
Run Code Online (Sandbox Code Playgroud)
没有节点也没有
kubectl label gke-kubia-default-pool-98519add-25c1/10.164.0.2 gpu=true
error: the server doesn't have a resource type "gke-kubia-default-pool-98519add-25c1"
Run Code Online (Sandbox Code Playgroud)
我认为该节点存在
Name: kubia-manual-v2
Namespace: default
Node: gke-kubia-default-pool-98519add-hsrc/10.164.0.2
Start Time: Fri, 08 Jun 2018 14:58:04 +0200
Run Code Online (Sandbox Code Playgroud)
如何设置标签?
如何列出可用节点?
这是从切片略微修改的代码
var buffer [256] byte
func SubtractOneFromLength(slice []byte) []byte {
slice = slice[0 : len(slice)-1]
return slice
}
func main() {
slice := buffer[10:20]
fmt.Println("Before: len(slice) =", len(slice))
newSlice := SubtractOneFromLength(slice)
fmt.Println("After: len(slice) =", len(slice))
fmt.Println("After: len(newSlice) =", len(newSlice))
newSlice2 := SubtractOneFromLength(newSlice)
fmt.Println("After: len(newSlice2) =", len(newSlice2))
}
Run Code Online (Sandbox Code Playgroud)
它表示slice参数的内容可以通过函数修改,但其标题不能.如何在屏幕上打印newSlice2的标题?
我有这样的数据
4.0 0.8
4.1 0.7
4.4 1.1
3.9 1.2
4.0 1.0
Run Code Online (Sandbox Code Playgroud)
我写了我的程序
#include <string>
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int main() {
vector<double> v;
ifstream in("primer.dat");
double word;
while(in >> word)
v.push_back(word);
for(int i = 0; i < v.size(); i++)
cout << v[i] << endl;
}
Run Code Online (Sandbox Code Playgroud)
但是现在我已经意识到,为了在我的代码中进一步计算,我需要数据(vector <vector> double)
.我宁愿不重塑矢量.是否可以将数据作为矢量矢量读取?
我的矢量中有1484个数值我想计算每个我有多少.数字从1到8.我试过这样的
#include <iostream>
#include <iterator>
#include <fstream>
#include <vector>
using namespace std;
int main(){
vector<int> res;
int sum1,sum2,sum3,sum4,sum5,sum6,sum7,sum8;
std::ifstream inputFile1("/home/milenko/cl.dat");
if (inputFile1) {
int value;
while ( inputFile1 >> value ) {
res.push_back(value);
}
}
switch (res) {
case 1:
sum1=sum1+1
break;
case 2:
sum2=sum2+1
break;
case 3:
sum3=sum3+1
break;
case 4:
sum4=sum4+1
break;
case 5:
sum5=sum5+1
break;
case 6:
sum6=sum6+1
break;
case 7:
sum7=sum7+1
break;
case 8:
sum8=sum8+1
break;
}
}
Run Code Online (Sandbox Code Playgroud)
但
error: switch quantity not an integer
switch …
Run Code Online (Sandbox Code Playgroud) 这是我迄今为止尝试过的
import itertools
import numpy as np
import matplotlib.pyplot as plt
with open('base.txt','r') as f:
vst = map(int, itertools.imap(float, f))
v1=vst[::3]
print type(v1)
a=np.asarray(v1)
print len(a)
a11=a.reshape(50,100)
plt.imshow(a11, cmap='hot')
plt.colorbar()
plt.show()
Run Code Online (Sandbox Code Playgroud)
我有 (50,100) 数组,每个元素都有数值(范围 1200-5400)。我想要代表数组的图像。但我得到了这个
我应该改变什么以获得正确的图像?
我的代码
import math
import itertools
with open('/home/milenko/OCCAM2DMT_V3.0/13042/ITER04.iter') as f:
lines_after_19 = f.readlines()[19:]
p = []
for line in lines_after_19:
line = line.split()
line = [float(i) for i in line]
p.extend(line)
a1=p[1:81]
for i in a1:
b1=math.pow(10, i)
a2=p[83:163]
for i in a2:
b2=math.pow(10,i)
a3=p[165:245]
for i in a3:
b3=math.pow(10,i)
a4=p[247:327]
for i in a4:
b4=math.pow(10,i)
a5=p[329:409]
for i in a5:
b5=math.pow(10,i)
a6=p[411:491]
for i in a6:
b6=math.pow(10,i)
c = itertools.chain(b1, b2, b3, b4, b5, b6)
print type(c)
Run Code Online (Sandbox Code Playgroud)
我需要将c转换为numpy
数组, …
文件看起来像这样
0 0 0
0 1 0
0 2 0
1 0 0
1 1 0
1 2 0
2 0 0
2 1 0
2 2 0
3 0 0
3 1 0
3 2 0
4 0 0
4 1 0
4 2 0
5 0 0
5 1 0
5 2 0
6 0 0
6 1 0
6 2 0
7 0 0
7 1 0
7 2 0
Run Code Online (Sandbox Code Playgroud)
我想修改
awk '$1 ="7" {print 100, $0}' …
Run Code Online (Sandbox Code Playgroud) 例如
grep -n 'integer*2' *.f
Run Code Online (Sandbox Code Playgroud)
什么也没看.但是
grep -n '*2' *.f
main.f:57: integer*2 itime(nxmax)
main.f:605: dxy=((xsource(is)-xobs)**2+(ysource(is)-yobs)**2)**.5
main.f:622: chisum=chisum+diff2/uobs**2
model.f:15: integer*2 veli(nxmax)
model.f:52: size2=size**2
time.f:151: integer*2 itime(nxmax)
Run Code Online (Sandbox Code Playgroud)
我真的不明白这一点.
我的代码
lines=[]
with open('biznism.txt') as outfile:
for line in outfile:
line = line.strip()
lines.append(line)
Run Code Online (Sandbox Code Playgroud)
这是我的 Jupyter 笔记本中的内容
["\ufeffIf we are all here, let's get started. First of all, I'd like you to please join me in welcoming Jack Peterson, our Southwest Area Sales Vice President.",
"Thank you for having me, I'm looking forward to today's meeting.",
"I'd also like to introduce Margaret Simmons who recently joined our team.",
'May I also introduce my assistant, Bob Hamp.',
"Welcome Bob. I'm afraid …
Run Code Online (Sandbox Code Playgroud)