如果我想获得两个数组的点积,我可以通过指定一个存储输出的数组而不是创建一个新数组来获得性能提升(如果我多次执行此操作)
import numpy as np
a = np.array([[1.0,2.0],[3.0,4.0]])
b = np.array([[2.0,2.0],[2.0,2.0]])
out = np.empty([2,2])
np.dot(a,b, out = out)
如果我需要修改数组,有什么办法可以利用这个功能吗?例如,如果我想:
out = np.array([[3.0,3.0],[3.0,3.0]])
out *= np.dot(a,b)
答案 0 :(得分:0)
是的,您可以使用import 'package:blackbox/models/candidate_model.dart';
import 'package:blackbox/screens/theme_page.dart' as t;
import 'package:flutter/material.dart';
class Login extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return new _Login();
}
}
class _Login extends State<Login> {
final _formKey = GlobalKey<FormState>();
String email, lastname, firstname;
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
leading: Image.asset(
'assets/img/logo_ineat.png',
fit: BoxFit.contain,
height: 32,
),
title: Text('BlackBox'),
),
body: new Center(
child: new SingleChildScrollView(
child: new Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
new Container(
margin: EdgeInsets.only(top: 10.0, bottom: 20.0),
alignment: Alignment.topCenter,
child: new Text('Se Connecter',
style: new TextStyle(
fontSize: 24, fontWeight: FontWeight.bold)),
),
new Card(
elevation: 10,
color: Colors.pink,
child: new Container(
width: MediaQuery.of(context).size.width / 2,
height: MediaQuery.of(context).size.height / 3,
child: new Image.asset('assets/img/logo_ineat.png',
fit: BoxFit.contain),
),
),
new Form(
key: _formKey,
child: new Column(
children: <Widget>[
new Row(
children: <Widget>[
new Container(
width: MediaQuery.of(context).size.width / 5,
margin:
EdgeInsets.only(left: 10, top: 5, right: 10.0),
child: new Text("Nom : "),
),
new Container(
width: MediaQuery.of(context).size.width / 1.4,
margin: EdgeInsets.only(top: 5, right: 10.0),
child: new TextFormField(
keyboardType: TextInputType.text,
decoration: new InputDecoration(
labelText: 'Entrez votre nom'),
validator: (value) {
if (value.isEmpty) {
return 'Veuillez remplir le champ nom';
}
lastname = value;
return null;
},
),
),
],
),
new Row(
children: <Widget>[
new Container(
width: MediaQuery.of(context).size.width / 5,
margin:
EdgeInsets.only(left: 10, top: 5, right: 10.0),
child: new Text("Prénom : "),
),
new Container(
width: MediaQuery.of(context).size.width / 1.4,
margin: EdgeInsets.only(top: 5, right: 10.0),
child: new TextFormField(
keyboardType: TextInputType.text,
decoration: new InputDecoration(
labelText: 'Entrez votre prénom'),
validator: (value) {
if (value.isEmpty) {
return 'Veuillez remplir le champ prénom';
}
firstname = value;
return null;
},
),
),
],
),
new Row(
children: <Widget>[
new Container(
width: MediaQuery.of(context).size.width / 5,
margin:
EdgeInsets.only(left: 10, top: 5, right: 10.0),
child: new Text("Email : "),
),
new Container(
width: MediaQuery.of(context).size.width / 1.4,
margin: EdgeInsets.only(top: 5, right: 10.0),
child: new TextFormField(
keyboardType: TextInputType.emailAddress,
decoration: new InputDecoration(
labelText: 'Entrez votre email'),
validator: (value) {
if (value.isEmpty) {
return 'Veuillez remplir le champ email';
}
email = value.toLowerCase();
return null;
},
),
),
],
),
new Container(
margin: EdgeInsets.only(top: 30, bottom: 5, right: 10.0),
alignment: Alignment.bottomRight,
child: new RaisedButton.icon(
onPressed: () {
setState(() async {
if (_formKey.currentState.validate()) {
Candidate newPost = new Candidate(
lastname: lastname,
firstname: firstname,
email: email,
);
var candidate = await Candidate()
.candidateAuth(body: newPost.toMap());
}
});
},
icon: Icon(Icons.check),
label: Text('Valider')),
),
],
),
),
],
),
),
),
);
}
}
参数来就地修改数组(例如out
),例如array=np.ones(10)
。
您甚至可以使用就地运算符语法,例如np.multiply(array, 3, out=array)
。
要确认阵列是否就地更新,可以在修改前后检查内存地址array *= 2
。