我试图做两个字典值的点积.例如:
dict_1={'a':2, 'b':3, 'c':5, 'd':2}
dict_2={'a':2, 'b':2, 'd':3, 'e':5 }
Run Code Online (Sandbox Code Playgroud)
在列表表单中,上面的内容如下所示:
dict_1=[2,3,5,2,0]
dict_2=[2,2,0,3,5]
Run Code Online (Sandbox Code Playgroud)
具有相同键的字典的点积将导致:
Ans= 16 [2*2 + 3*2 + 5*0 + 2*3 + 0*5]
Run Code Online (Sandbox Code Playgroud)
如何用字典实现这一目标?通过列表,我可以调用np.dot函数或编写一个小循环.
def applejuice(q):
print THE FUNCTION NAME!
Run Code Online (Sandbox Code Playgroud)
它应该导致"applejuice"作为一个字符串.
好的,我正在研究一种类型的系统,以便我可以使用sms消息在我的计算机上开始操作.我可以让它发送初始消息:
import smtplib
fromAdd = 'GmailFrom'
toAdd = 'SMSTo'
msg = 'Options \nH - Help \nT - Terminal'
username = 'GMail'
password = 'Pass'
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login(username , password)
server.sendmail(fromAdd , toAdd , msg)
server.quit()
Run Code Online (Sandbox Code Playgroud)
我只需要知道如何等待回复或从Gmail本身提取回复,然后将其存储在变量中以供以后的功能使用.
我是石墨烯的新手,我正在尝试将以下结构映射为对象类型,但完全没有成功
{
"details": {
"12345": {
"txt1": "9",
"txt2": "0"
},
"76788": {
"txt1": "6",
"txt2": "7"
}
}
}
Run Code Online (Sandbox Code Playgroud)
任何指导都非常
感谢
我的iPhone应用程序正在开发中遇到一个非常奇怪的崩溃.似乎每当我向朋友展示我的应用程序时它都会崩溃,但是否则它永远不会崩溃.在被墨菲的法律方面普遍迷惑之后,我已经确定了崩溃的模式 - 纽约市地铁.我使用地铁后,我的应用程序一直崩溃.我已将这个问题追溯到我的使用Reachability.应用程序在无网络情况(不包括飞行模式)下使用后,下次崩溃.Reachability在执行任何其他网络操作之前,我遵循Apple的指导原则并检查连接,但我发现了一些有关如何调用它的相互矛盾的文档.
目前我正在做这样的事情:
-(BOOL)reachable {
Reachability *r = [Reachability reachabilityWithHostName:@"www.stackoverflow.com"];
NetworkStatus internetStatus = [r currentReachabilityStatus];
if(internetStatus == NotReachable) {
return NO;
}
return YES;
Run Code Online (Sandbox Code Playgroud)
}
我正在调用与viewDidAppear调用的方法同步.
if ([self reachable]== YES) {
... do network stuff ...
Run Code Online (Sandbox Code Playgroud)
它基于iOS 4 Reachability Guide的代码
我的问题:是否正确使用Reachability它将处理此错误并处理缺少3G或Wifi网络?我是否需要生成另一个线程或执行某些操作来删除同步调用?
顺便说一句,这是我在应用程序崩溃时看到的崩溃日志,这让我认为这是一个同步/异步问题.
Application Specific Information: (app name) failed to resume in time Elapsed total CPU time (seconds): 3.280 (user 1.770, system 1.510), 33% CPU Elapsed application CPU time (seconds): 0.040, 0% …
嗨伙伴Djangonauts:
我用django-lint检查了我的项目,它产生了:
W:211,16:MyModel: timestamp: Uses superceded auto_now or auto_now_add
Run Code Online (Sandbox Code Playgroud)
在提交信息:
auto_now/auto_now_add not technically deprecated, but they still suck.
Run Code Online (Sandbox Code Playgroud)
为什么他们说auto_now/auto_now_add"吮吸"?使用这两个字段参数实现创建/上次更新的模式没有问题.
这种模式有更好的方法吗?自定义字段类?为什么(如果这种方法更好)它还没有被集成到Django中?
我正在尝试使用Http服务进行ajax调用,这工作正常.
现在我想处理失败案件.例如,如果我们得到404或任何其他错误.
我使用以下代码.
import {Component,Inject} from '@angular/core';
import {Http, Response,HTTP_PROVIDERS} from '@angular/http';
import {DoService} from './service';
import 'rxjs/Rx';
import 'rxjs/add/operator/catch';
@Component({
selector: 'comp-one',
template: `<h2>My First Angular 2 App</h2>{{data}}
<input type="button" (click)="doSomething()" value="Do Http"/>`
})
export class ComponentOne {
constructor(public _http:Http){
console.log("It is from ComponentOne constructor..");
this._http = _http;
}
data:Object;
doSomething(){
console.log("It is from doSomething ComponentOne");
let temp:any = this._http.get('people.json')//people.json is not exist, intendedly maing any error
.map(res => res.json())
.catch((err:any)=>{ console.log("Something is wrong..")});// If i keep this line …Run Code Online (Sandbox Code Playgroud) 我想知道为什么 Relay 规范在 graphene-django 中?我知道在 graphene-django 中使用中继我们默认获得分页和过滤器。
我的要求是从 React(用于 Web)调用 graphql apis 并使用适用于 Android 和 iOS 的 Apollo 客户端。
客户端使用具有 Relay 兼容特别是分页(和游标)功能的 graphene-django 编写的 graphql api 会不会有问题?
如何使用graphene-django支持订阅?
任何帮助将不胜感激。
运行Rake测试时,我会在参考YAML文件时遇到一些错误.关于如何修复它的任何想法?
运行测试:EEEEEEEE
完成测试0.070970s,112.7237次测试/秒,0.0000断言/秒.
1) Error: test_should_create_product(ProductsControllerTest): ActiveRecord::Fixture::FormatError: a YAML error occurred parsing /Users/ka/src/ruby-test/depot/test/fixtures/products.yml. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Please have a look at yaml.org/faq.html The exact error was: Psych::SyntaxError: (): found character that cannot start any token while scanning for the next token at line 5 column 1 /Users/ka/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/fixtures/file.rb:43:in rows' /Users/ka/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/fixtures/file.rb:29:ineach' /Users/ka/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/fixtures.rb:670:in block (2 levels) in read_fixture_files' /Users/ka/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/fixtures/file.rb:20:inopen' /Users/ka/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/fixtures.rb:669:in block in read_fixture_files' /Users/ka/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/fixtures.rb:668:in each' /Users/ka/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/fixtures.rb:668:in read_fixture_files' /Users/ka/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/fixtures.rb:548:in initialize' /Users/ka/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/fixtures.rb:482:in new' /Users/ka/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/fixtures.rb:482:in …
我正在尝试这样做:
类 NoClearableFileInput(ClearableFileInput):
初始文本 = ''
输入文本 = ''
类 ImageUploadForm(forms.ModelForm):
title = forms.CharField(label="TITLE", required=False,widget=forms.TextInput(attrs={'placeholder': 'name'}), label_suffix="")
image = forms.ImageField(label='NEW FILE',widget=NoClearableFileInput, label_suffix="")
元类:
模型 = 图像
字段 = ('标题','图片')
在类 NoClearableFileInput 中清除了初始值initial_text。在字段 'title' 和 'image' 中使用 label_suffix,但来自 initial_text 的符号“:”仍然存在。
如何摆脱冒号?