典型的AJAX和Fetch API有什么区别?
考虑这种情况:
function ajaxCall(url) {
return new Promise(function(resolve, reject) {
var req = new XMLHttpRequest();
req.open('GET', url);
req.onload = function() {
if (req.status == 200) {
resolve(req.response);
} else {
reject(Error(req.statusText));
}
};
req.onerror = function() {
reject(Error("Network Error"));
};
req.send();
});
}
ajaxCall('www.testSite').then(x => {
console.log(x)
}) // returns html of site
fetch('www.testSite').then(x => {
console.log(x)
}) // returns object with information about call
Run Code Online (Sandbox Code Playgroud)
这是fetch调用返回的内容:
Response {type: "cors", url: "www.testSite", status: 200, ok: true, statusText: "OK"…} …Run Code Online (Sandbox Code Playgroud) 我试图使用连接两个节点列表
var ul = document.querySelector("ul");
var down = document.getElementsByClassName("mobile")[0];
var ul_child = Array.prototype.concat.call(ul.children,down.children);
Run Code Online (Sandbox Code Playgroud)
但是这只返回ul nodelist中的两个节点而忽略其他节点.连接两个nodelsits最有效的是什么?我想避免粗暴地循环它们
我试图使用node.js - nodemailer模块发送电子邮件,我的整个代码看起来像
var http=require("http");
var nodemailer=require("nodemailer");
http.createServer(function(req,res){
res.writeHead(200, {"Content-Type": "text/plain"});
var transporter = nodemailer.createTransport('SMTP',{
service: 'gmail',
auth: {
user: 'myemail@gmail.com', // my mail
pass: 'mypassword'
}
});
var mailOptions = {
from: 'Fred Foo ? <foo@blurdybloop.com>', // sender address
to: 'myemail@gmail.com', // the same mail = want to send it to myself
subject: 'Hello ?', // Subject line
text: 'Hello world ?', // plaintext body
html: '<b>Hello world ?</b>' // html body
};
transporter.sendMail(mailOptions, function(error, info){
if(error){
return console.log(error); …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建自己的损失函数:
def custom_mse(y_true, y_pred):
tmp = 10000000000
a = list(itertools.permutations(y_pred))
for i in range(0, len(a)):
t = K.mean(K.square(a[i] - y_true), axis=-1)
if t < tmp :
tmp = t
return tmp
Run Code Online (Sandbox Code Playgroud)
它应该创建预测向量的排列,并返回最小的损失.
"`Tensor` objects are not iterable when eager execution is not "
TypeError: `Tensor` objects are not iterable when eager execution is not enabled. To iterate over this tensor use `tf.map_fn`.
Run Code Online (Sandbox Code Playgroud)
错误.我找不到任何此错误的来源.为什么会这样?
谢谢你.
python artificial-intelligence neural-network conv-neural-network keras
使用媒体查询检测视网膜显示并指定的最佳方法是什么max-width?我可以使用检测视网膜
@media
only screen and (-webkit-min-device-pixel-ratio: 2),
only screen and ( min--moz-device-pixel-ratio: 2),
only screen and ( -o-min-device-pixel-ratio: 2/1),
only screen and ( min-device-pixel-ratio: 2),
only screen and ( min-resolution: 192dpi),
only screen and ( min-resolution: 2dppx) {
}
Run Code Online (Sandbox Code Playgroud)
如何将其添加到媒体查询?我写的吗?
@media
only screen and (-webkit-min-device-pixel-ratio: 2),
only screen and ( min--moz-device-pixel-ratio: 2),
only screen and ( -o-min-device-pixel-ratio: 2/1),
only screen and ( min-device-pixel-ratio: 2),
only screen and ( min-resolution: 192dpi),
only screen and ( min-resolution: 2dppx) {
@media …Run Code Online (Sandbox Code Playgroud) 我有一个输入图像416x416.如何创建4 x 10的输出,其中4是列数,10是行数?
我的标签数据是包含4列10行的2D数组.
我知道该reshape()方法,但它要求结果形状具有与输入相同数量的元素.
使用416 x 416输入大小和最大池层,我可以获得最大13 x 13输出.
有没有办法在4x10不丢失数据的情况下实现输出?
我的输入标签数据类似于
[[ 0 0 0 0]
[ 0 0 0 0]
[ 0 0 0 0]
[ 0 0 0 0]
[ 0 0 0 0]
[ 0 0 0 0]
[ 0 0 0 0]
[116 16 128 51]
[132 16 149 52]
[ 68 31 77 88]
[ 79 34 96 92]
[126 37 147 112]
[100 41 126 116]]
Run Code Online (Sandbox Code Playgroud)
这表示我想要检测的图像上有6个对象,第一个值是xmin,第二个ymin,第三个xmax,第四个ymax. …
python artificial-intelligence neural-network conv-neural-network keras
我正在做小马赛克(如果我可以这样称呼它).我正在根据位置鼠标和图片/ div的中心改变比例和不透明度.
我正在通过vektors计算距离
function calculateDistance(elem, mouseX, mouseY) {
return Math.floor(Math.sqrt(Math.pow(mouseX - (elem.offsetLeft + (elem.offsetWidth / 2)), 2) + Math.pow(mouseY - (elem.offsetTop + (elem.offsetHeight / 2)), 2)));
}
Run Code Online (Sandbox Code Playgroud)
并且我循环遍历div /图片,如果距离小于100,则计算其不透明度/比例.
但是我遇到了一个问题,即不透明度/比例变化的动画有点不稳定.如果它应该做某事似乎犹豫不决.
演示= http://jsfiddle.net/Trolstover/x9fpv8pb/5/
是否有任何方法或捷径如何解决,因为我称之为摇晃或犹豫?
我正在使用不应弹出两次的数据.如果是,它应该检测它并调用一个处理它的函数.
目前,我正在将一些数据推送到矢量,在插入之前,它应检查数据是否已包含在该矢量中.目前,这不是很有效,例如
for (int i = 0; i < myVector.size() ; i++)
{
if ( myVector[i] == data )
{
// invoke function
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
我知道这set是一种特殊的矢量,它只允许唯一的数据.
是否有另一种方法来检测添加(或至少尝试添加)重复数据到set?
有结构
struct Person{
Person( int i , int g):id(i),age(g){};
int id;
int age;
};
Run Code Online (Sandbox Code Playgroud)
我可以通过将指向成员数据的指针作为参数传递给函数来动态返回成员数据.例如
int extract( Person * p , int Person::* param)
{
return p ->*param;
}
Run Code Online (Sandbox Code Playgroud)
并使用
Person *p = new Person (10 , 20 );
cout << extract(p , &Person::id )<< endl;
Run Code Online (Sandbox Code Playgroud)
但我的问题是,为什么这有效?我们传递&Person::id基本的内存,但是Person是一个违背定义的r值.
我感谢所有对我可能对主题的误解的解释/澄清.谢谢.
在c ++中从函数返回值的幕后是什么?
在我的理解中每当func.被称为返回地址和堆栈帧(具有局部变量,func.参数和寄存器的被调用顺序)被推送到调用堆栈.
但是当执行遇到返回statemenet时会发生什么?例如
int a( int b ){
int c = b * 2;
return c;
}
Run Code Online (Sandbox Code Playgroud)
遇到return语句后,存储在EAX寄存器中的C值是否被破坏,局部变量被破坏,堆栈帧从调用堆栈中删除,之后EAX寄存器中的值被移入"返回地址"内存?
或者我误解了这个概念?
所有帮助都非常感谢.谢谢.