laiqun / laiqun.github.io

0 stars 0 forks source link

解决matplot绘制过慢 #14

Open laiqun opened 5 years ago

laiqun commented 5 years ago

之前的代码

x=np.asarray(label_value)
                y=np.arange(len(label_value))
                fig=plt.figure()
                plt.plot(x,y)
                plt.show()

是这样的

xit=iter(label_value)
                yit=iter(np.arange(len(label_value)))
                #x=np.asarray(label_value)
                x=np.fromiter(xit,dtype=int)
                y=np.fromiter(yit,dtype=int)

                fig=plt.figure()
                plt.plot(x,y)
                plt.savefig("D:/temp.png")
                plt.show()

改了之后是这样的

图形秒出

我明白了

类似于range 和xrange

laiqun commented 5 years ago

http://47.106.163.82/wp-content/uploads/2019/01/%E5%88%A9%E7%94%A8python%E8%BF%9B%E8%A1%8C%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90-%E7%AC%AC%E4%BA%8C%E7%89%88.pdf

laiqun commented 5 years ago

首先要理解promise: https://www.liaoxuefeng.com/wiki/1022910821149312/1023024413276544 promise表示函数立即执行,然后用then和catch传入成功和错误处理的函数。 然后理解generate: fun*(){ while(true){ yield; } } g = fun(); //g是一个generate对象,然后每次调用g.next都会执行到yield返回。

  1. async 和await https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await await会把后面的东西强制转换为Promise,当其变为fulfullied的时候,函数向下执行。调用resolve或reject是必须的。此时resove代表这个函数的next执行。await的返回值,就是resolve中传入的参数。
    async function aa()
    {
    console.log("aa");
    await new Promise(resolve=>{  setTimeout(  ()=>{console.log("xx");resolve("ok");},10   )});
    console.log("bb");
    }
laiqun commented 5 years ago

"google.com, pub-8319785630586631, DIRECT, f08c47fec0942fa0"

laiqun commented 4 years ago

http://ahmed-badawy.com/blog/wp-content/uploads/2018/10/Cracking-the-Coding-Interview-6th-Edition-189-Programming-Questions-and-Solutions.pdf

laiqun commented 4 years ago

https://edu.15kankan.com/info/0bw729052

laiqun commented 4 years ago

(async() => { await setLocalStorage({ aaa: 1, bbb: 2 });

let aaa = await getLocalStorage("aaa");
let bbb = await getLocalStorage("bbb");
let all = await getLocalStorage();

console.log(aaa);// 1
console.log(bbb);// 2
console.log(all);// {aaa: 1, bbb: 2}

})();

function setLocalStorage(obj) { return new Promise( (resolve) => { chrome.storage.local.set( obj, () => resolve() ); }); }

function getLocalStorage(key = null) { return new Promise( (resolve) => { chrome.storage.local.get(key, (item) => { key ? resolve(item[key]) : resolve(item); }); }); }

laiqun commented 4 years ago

for (let i =0;i<8;i++) chrome.tabs.create({"active":false,'url':"http://127.0.0.1/"+i}); let newTabsId=[]; let tabsState ={};//ready ; wait两种选项 chrome.tabs.onCreated.addListener(function(tab) { newTabsId.push(tab.id); newTabsId["tab.id"] = "ready"; if(newTabsId.length == 8)//8个tab已经创建完成,开始浏览页面 { for (const iterator of newTabsId) { chrome.tabs.update(iterator,{url:"http://127.0.0.1/"+iterator}); //只要打开url即可,content script 会自动把数据抓好,给background //content script怎么知道数据可以抛了呢? //发信息确认一下后台的stage } } }); //爬完后关闭所有的tab for (const iterator of newTabsId) { chrome.tabs.remove(iterator); }

// 监听来自content-script的消息 chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { console.log('收到来自content-script的消息:'); console.log(request, sender, sendResponse); sendResponse('我是后台,我已收到你的消息:' + JSON.stringify(request)); //可以得知哪个url已经完成,如果完成,那就把该标签卡的状态,设置为ready,表示可以接下一次任务了

});

laiqun commented 4 years ago

https://www.cnblogs.com/lvdabao/p/es6-promise-1.html